⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertyeventpanel.java

📁 270的linux说明
💻 JAVA
字号:
/*

Copyright (c) 2008, Intel Corporation. 

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:


    * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution.

    * Neither the name of Intel Corporation nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.

*/import java.awt.Component;import java.util.Vector;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.table.AbstractTableModel;import javax.swing.table.TableCellRenderer;import javax.swing.table.TableColumn;import com.intel.mobile.base.InstanceObject;import com.intel.mobile.base.IntelMobileException;import com.intel.mobile.base.Property;import com.intel.mobile.battery.BatteryInstance;/* * Created on 2004-11-22 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates *//** * @ * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */public class PropertyEventPanel extends JPanel {		public JPropertyEventListPanel PropertyEventPanel = null;	private JPanel ButtonPanel=null;	private int ButtonInterval=10;	private int ButtonWidth=140;	private int PanelWidth=620;	/**	 * This is the default constructor	 */	public PropertyEventPanel() {		super();		initialize();	}	/**	 * This method initializes this	 * 	 * @return void	 */	private  void initialize() {		this.setSize(600, 350);		this.setLayout(/*new java.awt.BorderLayout()*/null);        this.add(getPropertyEventPanel());// BorderLayout.NORTH);        this.add(getButtonPanel());//, BorderLayout.SOUTH);	}		private JPropertyEventListPanel getPropertyEventPanel()	{		if(PropertyEventPanel==null)		{			PropertyEventPanel=new JPropertyEventListPanel();						//PropertyEventPanel.setSize(520,300);			PropertyEventPanel.setBounds(0,0,PanelWidth,300);		}				return PropertyEventPanel;	}		private JPanel getButtonPanel()	{		if(ButtonPanel==null)		{			ButtonPanel=new JPanel();			//ButtonPanel.setSize(520,44);			ButtonPanel.setBounds(0,300,PanelWidth, 50);			ButtonPanel.setLayout(/*new java.awt.BorderLayout()*/null);			ButtonPanel.add(getRegisterButton());						//ButtonPanel.setLayout(new BoxLayout(ButtonPanel, BoxLayout.X_AXIS));			//ButtonPanel.add(Box.createRigidArea(VGAP15)); 			ButtonPanel.add(getUnRegisterButton());			ButtonPanel.add(getRegisterAllButton());			ButtonPanel.add(getUnRegisterAllButton());		}				return ButtonPanel;	}		private JButton getRegisterButton()	{		JButton a = new JButton("Register");		a.setBounds(ButtonInterval,10,ButtonWidth, 25);		a.addActionListener(new java.awt.event.ActionListener() { 			public void actionPerformed(java.awt.event.ActionEvent e) {    				int selectedRow=PropertyEventPanel.jTable.getSelectedRow();				if(selectedRow>=0)				{					PropertyEventPanel.dataModel.registerEvent(selectedRow);					PropertyEventPanel.jTable.repaint();				}							}		});					return a;			}		private JButton getUnRegisterButton()	{		JButton a = new JButton("UnRegister");		a.setBounds(ButtonWidth+2*ButtonInterval,10,ButtonWidth, 25);		a.addActionListener(new java.awt.event.ActionListener() { 			public void actionPerformed(java.awt.event.ActionEvent e) {    				int selectedRow=PropertyEventPanel.jTable.getSelectedRow();				if(selectedRow>=0)				{					PropertyEventPanel.dataModel.unregisterEvent(selectedRow);					PropertyEventPanel.jTable.repaint();				}			}		});					return a;			}		private JButton getRegisterAllButton()	{		JButton a = new JButton("Register ALL");		a.setBounds(2*ButtonWidth+3*ButtonInterval,10,ButtonWidth, 25);		a.addActionListener(new java.awt.event.ActionListener() { 			public void actionPerformed(java.awt.event.ActionEvent e) {    				PropertyEventPanel.dataModel.registerALLEvent();				PropertyEventPanel.jTable.repaint();			}		});					return a;	}		private JButton getUnRegisterAllButton()	{		JButton a = new JButton("UnRegister  ALL");		a.setBounds(3*ButtonWidth+4*ButtonInterval,10,ButtonWidth, 25);		a.addActionListener(new java.awt.event.ActionListener() { 			public void actionPerformed(java.awt.event.ActionEvent e) {    				PropertyEventPanel.dataModel.unregisterALLEvent();				PropertyEventPanel.jTable.repaint();			}		});					return a;	}			/**	 * internal class	 * <class or interface desc>	 */	class JPropertyEventListPanel extends JPanel	{	    private JScrollPane jScrollPane = null;	    private JTable jTable = null;	    public JPropertyTableModel dataModel = new JPropertyTableModel();	    	    private BatteryInstance myInstance = null;	    	    /**	     * Constructor	     * @param myInstance	     */	    JPropertyEventListPanel()	    {	        //TODO:	        this.setLayout(new java.awt.BorderLayout());	        this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);	    }	    	    private void refresh() throws IntelMobileException	    {	        dataModel.initialize();	    }	    	    /**	     * This method initializes jScrollPane	     * 	     * @return javax.swing.JScrollPane	     */	    private JScrollPane getJScrollPane()	    {	        if (jScrollPane == null)	        {	            jScrollPane = new JScrollPane();	            jScrollPane.setViewportView(getJTable());	            try				{	            	//Refresh property event list to show items	            	this.refresh();				}		        catch (IntelMobileException ex)		        {		            ex.printStackTrace();		        }	        }	        return jScrollPane;	    }	    	    public class CheckListItem        {            boolean check;            String text;            public CheckListItem(boolean check, String text)            {                this.check = check;                this.text = text;            }            public boolean getCheck() { return check; }            public void setCheck(boolean _check) { check = _check; }            public String getText() { return text; }            public void setText(String _text) { text = _text; }        }	    	    public class eventItem		{	    	CheckListItem checkItem;	    	String Comment;	    	public eventItem(boolean check, String text, String Comment)	    	{	    		this.checkItem=new CheckListItem(check,text);	    		this.Comment=Comment;	    	}	    	public CheckListItem getcheckItem(){return checkItem;}	    	public void setcheckItem(CheckListItem _checkItem){checkItem=_checkItem;}	    	public String getComment(){return Comment;}	    	public void setComment(String _Comment){Comment=_Comment;}		}                public class CheckListItemRenderer extends JCheckBox implements TableCellRenderer        {	            public Component getTableCellRendererComponent(                        JTable table,                        Object value,                        //int index,                        boolean isSelected,                        boolean hasFocus,						int row,						int column)            {                CheckListItem item = (CheckListItem)value;                this.setSelected(item.getCheck());                this.setText(item.getText());                this.setFont(table.getFont());                this.setEnabled(table.isEnabled());                                return this;            }        }        	    /**	     * This method initializes jTable	     * 	     * @return javax.swing.JTable	     */	    private JTable getJTable()	    {	        if (jTable == null)	        {	            jTable = new JTable(dataModel);	            	            TableColumn CheckBoxColumn = jTable.getColumn("Name"); 	            CheckBoxColumn.setCellRenderer(new CheckListItemRenderer());           	        }	        return jTable;	    }	    		/**	     * internal class	     * <class or interface desc>	     */	    class JPropertyTableModel extends AbstractTableModel		{	    		    	public class propertyEventItem			{				public Property Property;				public String EventName;				public InstanceObject Instance;							public propertyEventItem()				{									}								public propertyEventItem(Property _property, String _EventName, InstanceObject _Instance)				{					Property=_property;					EventName=_EventName;					Instance=_Instance;				}								private void setProperty(Property _property){Property=_property;}				private Property getProperty(){return Property;}				private void setEventName(String _EventName){EventName=_EventName;}				private String getEventName(){return EventName;}				private void setInstance(InstanceObject _Instance){Instance=_Instance;}				private InstanceObject getInstance(){return Instance;}			}		    	        private final String[] names = { "Name", "Comment" };        private Vector vectCheckBoxEvent=new Vector();        public Vector vectEventCollection=new Vector();                JPropertyTableModel()		{        		}        // These methods always need to be implemented.                //Add Event items to eventlist        public void addEventItem(Property property, String EventName, String Comment,InstanceObject Instance)        {        	try			{        	if(!property.IsNull() && !property.IsStatic())        	{	        	//cache the evet item list	        	propertyEventItem eventItem=new propertyEventItem(property,EventName,Instance);	        	vectEventCollection.add(eventItem);	        		        	//show the event item on the screen	            eventItem Item=new eventItem(false,EventName,Comment);	            vectCheckBoxEvent.add(Item);        	}			}catch (Exception e)			{							}        }                //Register function event        public void registerEvent(int index)        {        	try			{	        	eventItem Item=(eventItem)vectCheckBoxEvent.get(index);	        	if(Item.checkItem.check==true)	        	{	        		return;//Already registered	        	}	        	//Register event	        	propertyEventItem eventItem=(propertyEventItem)vectEventCollection.get(index);	        	eventItem.Property.Changed.AddObserver(MainFrame.clObserver);	        		        	//Set event register signal	        	Item.checkItem.check=true;			}        	catch(IntelMobileException e)			{        					}        	        }                public void registerALLEvent()        {        	for(int i=0;i<vectCheckBoxEvent.size();i++)        	{        		registerEvent(i);        	}        }        //      UnRegister function event        public void unregisterEvent(int index)        {        	try			{	        	eventItem Item=(eventItem)vectCheckBoxEvent.get(index);	        	if(Item.checkItem.check==false)	        	{	        		return;//Already unregistered	        	}	        	//UnRegister event	        	propertyEventItem eventItem=(propertyEventItem)vectEventCollection.get(index);	        	eventItem.Property.Changed.RemoveObserver(MainFrame.clObserver);	        		        	//Set event unregister signal	        	Item.checkItem.check=false;			}        	catch(IntelMobileException e)			{        					}        	        }                public void unregisterALLEvent()        {        	for(int i=0;i<vectCheckBoxEvent.size();i++)        	{        		unregisterEvent(i);        	}        }        public int getColumnCount()        {            return names.length;        }        public int getRowCount()        {            return vectCheckBoxEvent.size();//data.length;        }        public Object getValueAt(int row, int col)        {        	if(col==0)        	{        		return ((eventItem)vectCheckBoxEvent.get(row)).checkItem;        	}else        	{        	        		return ((eventItem)vectCheckBoxEvent.get(row)).Comment;        	}        }        // The default implementations of these methods in        // AbstractTableModel would work, but we can refine them.        public String getColumnName(int column)        {            return names[column];        }        public Class getColumnClass(int col)        {            return String.class;            //return getValueAt(0, col).getClass();        }        public boolean isCellEditable(int row, int col)        {            return false;        }        // ------------- initialize --------------        public void initialize() throws IntelMobileException        {        	        }	}	}}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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