📄 thresholdspanel.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.util.Vector;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.table.AbstractTableModel;import com.intel.mobile.base.InstanceObject;import com.intel.mobile.base.IntelMobileException;import com.intel.mobile.base.Property;import com.intel.mobile.base.Threshold;import com.intel.mobile.battery.BatteryInstance;import com.intel.mobile.base.Event;import com.intel.mobile.base.EventType;import java.util.Observable;import java.util.Observer;//import com.intel.mobile.threshold.CounterThreshold;/** * @ * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */public class ThresholdsPanel extends JPanel { public JThresholdListPanel PropertyEventPanel = null; private JPanel ButtonPanel=null; private int ButtonInterval=10; private int ButtonWidth=140; private int PanelWidth=620; private Watcher observing = new Watcher(); public class propertyItem { public String propertyName; public Property property; propertyItem(String _propertyName, Property _property) { propertyName=_propertyName; property=_property; } } private Vector vectPropertyCollection=new Vector(); /** * This is the default constructor */ public ThresholdsPanel() { super(); initialize(); MainFrame.clObserver.observed.addObserver(observing); } public static void registerCounterThreshold(Property property, int MatchValue, int rate,boolean IsMatchNotify) { //TODO: //CounterThreshold threshold=new CounterThreshold(); } public void addPropertyItem(Property property) { try { if(!property.IsNull() && !property.IsStatic()) { propertyItem item=new propertyItem(property.GetName(),property); vectPropertyCollection.add(item); } } catch(IntelMobileException e) { } } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(600, 350); this.setLayout(/*new java.awt.BorderLayout()*/null); this.add(getThresholdPanel());// BorderLayout.NORTH); this.add(getButtonPanel());//, BorderLayout.SOUTH); } private JThresholdListPanel getThresholdPanel() { if(PropertyEventPanel==null) { PropertyEventPanel=new JThresholdListPanel(); //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(getAddButton()); //ButtonPanel.setLayout(new BoxLayout(ButtonPanel, BoxLayout.X_AXIS)); //ButtonPanel.add(Box.createRigidArea(VGAP15)); ButtonPanel.add(getRemoveButton()); // ButtonPanel.add(getEditButton()); ButtonPanel.add(getRemoveAllButton()); } return ButtonPanel; } private JButton getAddButton() { JButton a = new JButton("Add"); a.setBounds(ButtonInterval,10,ButtonWidth, 25); a.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { NewThresholdDlg newThreshold=new NewThresholdDlg(vectPropertyCollection,PropertyEventPanel.dataModel); newThreshold.setModal(true); newThreshold.setLocationRelativeTo(null); newThreshold.show(); refreshUI(); } }); return a; } private void refreshUI() { this.initialize(); } private JButton getRemoveButton() { JButton a = new JButton("Remove"); 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 != -1) { getThresholdPanel().dataModel.removeThreshold(selectedRow); getThresholdPanel().jTable.repaint(); getThresholdPanel().jTable.clearSelection(); refreshUI(); } } }); return a; } /* private JButton getEditButton() { JButton a = new JButton("Edit"); a.setBounds(2*ButtonWidth+3*ButtonInterval,10,ButtonWidth, 25); a.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { int selectedRow=PropertyEventPanel.jTable.getSelectedRow(); String mypropertyname; mypropertyname = getThresholdPanel().dataModel.getValueAt(selectedRow, 0).toString(); EditThresholdDlg editThreshold=new EditThresholdDlg(vectPropertyCollection,mypropertyname,PropertyEventPanel.dataModel); editThreshold.setModal(true); editThreshold.setLocationRelativeTo(null); editThreshold.show(); if(editThreshold.okFlag == 1) { getThresholdPanel().dataModel.removeThreshold(selectedRow); getThresholdPanel().jTable.repaint(); } refreshUI(); } }); return a; } */ private JButton getRemoveAllButton() { JButton a = new JButton("Remove 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) { getThresholdPanel().dataModel.removeALLThreshold(); getThresholdPanel().jTable.repaint(); refreshUI(); } }); return a; } /** * internal class * <class or interface desc> */ class JThresholdListPanel extends JPanel { private JScrollPane jScrollPane = null; private JTable jTable = null; public JPropertyTableModel dataModel = new JPropertyTableModel(); /** * Constructor * @param myInstance */ public JThresholdListPanel() { 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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -