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

📄 guipanel.java

📁 用于传感器网络的节点操作系统 TinyOS 结构设计非常有意思
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    public void triggerCheckBoxAction() {	if (triggerCheckBox.isSelected()) { //user selected the box	    if (checkSelectionConsistency(selectDestList,null)) {		triggerActionBox.setEnabled(true);		triggerLabel.setEnabled(true);	    } else {		triggerCheckBox.setSelected(false);	    }	} else { //user deselected the box	    if (checkSelectionConsistency(selectDestList,null)) {		triggerActionBox.setEnabled(false);		triggerLabel.setEnabled(false);	    } else {		triggerCheckBox.setSelected(true);	    }	}		//update the aggregate operators available for the current source selection	selectSrcListAction();		//refresh the SQL clause to reflect this change	updateSQL();	    }        /** Called when the "-" button to remove a where clause is pressed */    public void removeWhereButtonActionPerformed(ActionEvent evt, int panelId) {	boolean removed = false;	for (int i = 0; i < panels.length; i++) {	    if (!removed) {		if (panels[i] != null && panels[i].getId() == panelId) {		    numPanels--;		    selectGroupPanel.remove(panels[i]);		    		    panels[i] = null;		    removed = true;		    validate();		} 	    } else {		if (panels[i] != null) panels[i].setId(panels[i].getId() - 1);		panels[i-1] = panels[i];		panels[i] = null;	    }	}	repaint();	updateSQL();    }        /** Called when the "<<<" to remove a selection attribute is clicked */    private void removeSelButtonActionPerformed(ActionEvent evt) {	Object value = selectDestList.getSelectedValue();	if (value != null) {	    Vector values = new Vector();	    ListModel model = selectDestList.getModel();	    for (int i = 0; i < model.getSize(); i++) {		if(model.getElementAt(i) != value)		    values.addElement(model.getElementAt(i));	    }	    selectDestList.setListData(values);	}      	updateSQL();    }            /** Called when the ">>>" to add a selection attribute is clicked */    private void addSelButtonActionPerformed(ActionEvent evt) {	QueryField value = (QueryField)selectSrcList.getSelectedValue();	AggOp op;		if (aggregateBox.getSelectedItem().toString().equals("None"))	    op = null;	else	    op = (AggOp)aggregateBox.getSelectedItem();		if (value != null) {	    SelectionField sf = new SelectionField(op, value);	    if (op == null || checkSelectionConsistency(selectDestList,sf)) {		Vector values = new Vector();		ListModel model = selectDestList.getModel();		for (int i = 0; i < model.getSize(); i++) {		    values.addElement(model.getElementAt(i));		}		values.addElement(sf);		selectDestList.setListData(values);	    }	}	updateSQL();    }        int oldIdx = -1;    boolean oldGrouping = false;    int oldGroupIdx = -1;            /** Called when something happens in the attribute selection list --	main goal is to constrain the aggregate operations menu so that	only valid aggregate choices are available.    */    private void selectSrcListAction() {	int idx = selectSrcList.getMinSelectionIndex();	boolean grouping = groupCheckBox.isSelected();	int groupIdx = groupBox.getSelectedIndex();		if (idx != oldIdx || grouping != oldGrouping || oldGroupIdx != groupIdx) {	    oldIdx = idx;	    oldGroupIdx = groupIdx;	    oldGrouping = grouping;	    	    updateSQL();	    	    constrainAggMenu(aggregateBox, grouping, groupIdx == idx, hasAgg());	}    }        /** Limit the items available in the aggregation menu based	on whether we're grouping or not    */    private void constrainAggMenu(JComboBox menu, boolean grouping, boolean groupbyField,  boolean hasAgg) {	menu.removeAllItems();		for (int i = 0; i < aggs.length; i++) {	    if (grouping && groupbyField) { //must not be an agg		if (aggs[i] == null) 		    menu.addItem("None");	    } else {		if (hasAgg || grouping) { //must be an agg		    if (aggs[i] != null)			menu.addItem(aggs[i]);		} else {		    if (aggs[i] == null)			menu.addItem("None");		    else			menu.addItem(aggs[i]);		}	    }	}    }                /** Called when the grouping check box is selected / deselected	Have to make sure that this is OK (can't have agg / non agg fields in same	if not grouping.    */    private void groupCheckBoxAction(ActionEvent evt) {	if (groupCheckBox.isSelected()) { //user selected the box	    if (checkSelectionConsistency(selectDestList,null)) {		groupBox.setEnabled(true);		groupLabel.setEnabled(true);		groupByOps.setEnabled(true);	    } else {		groupCheckBox.setSelected(false);	    }	} else { //user deselected the box	    if (checkSelectionConsistency(selectDestList,null)) {		groupBox.setEnabled(false);		groupLabel.setEnabled(false);		groupByOps.setEnabled(false);		groupByConst.setEnabled(false);	    } else {		groupCheckBox.setSelected(true);	    }	}		//update the attribute lists to reflect group by operators	//updateAttributeLists();	//update the aggregate operators available for the current source selection	selectSrcListAction();		//refresh the SQL clause to reflect this change	updateSQL();    }            //User added a selection predicate -- create the new panel (if there's a slot for it.)    private void newPredButtonActionPerformed(ActionEvent evt) {	JPanel newPanel = null;		if (numPanels < 3) {	    newPanel = new WherePanel(numPanels, this);	    panels[numPanels++] = (WherePanel)newPanel;	} else {	    setError("At most three selection predicates allowed per query.");	}		if (newPanel != null) {	    selectGroupPanel.add(newPanel);	    	    validate();	}			repaint();	updateSQL();    }            /** Add the available arithmetic operations to the menu */    public void addArithOpsToMenu(JComboBox menu) {	for (int i = 0; i < arithOps.length; i++) {	    menu.addItem(arithOps[i]);	}    }            /** Add the available query fields (from the catalog) to the menu */    public void addFieldsToMenu(JComboBox menu) {	for (int i = 0; i < Catalog.curCatalog.numAttrs(); i++) {	    menu.addItem(Catalog.curCatalog.getAttr(i));	}    }        /** Add the available selection operators to the specified menu */    public void addOpsToMenu(JComboBox menu) {	for (int i = 0; i < ops.length; i++) {	    menu.addItem(ops[i]);	}    }        /** Add the vailable aggregate operators to the specified menu */    private void addAggsToMenu(JComboBox menu) {	for (int i = 0; i < aggs.length; i++) {	    if (aggs[i] == null)		menu.addItem("None");	    else		menu.addItem(aggs[i]);	}	    }        /** Add the available epoch durations to the menu */    private void addEpochsToMenu(JComboBox menu) {	int es[] = {64,128,256,512,1024,2048,4096,8192,16384};	for (int i =0 ; i < es.length; i++)	    menu.addItem(new Integer(es[i]));	menu.setSelectedIndex(4);    }            /** Add the available selection attributes to the specific list */    private void addSelectChoices(JList list) {	Vector fields = new Vector();		for (int i = 0; i < Catalog.curCatalog.numAttrs(); i++) {	    fields.add(Catalog.curCatalog.getAttr(i));	}		list.setListData(fields);	    }        /** Given a list of current attrs in the query and a (possibly null) attr to add	to that list, return true iff the addition is OK (or newf == null) AND 	the current settings (e.g. grouping, group by field, etc) are consistent.		Return false otherwise.		This is used extensively to determine if some user action produces a consistent	query.  It sets appropriate error messages when consistency checks fail.    */    public boolean checkSelectionConsistency(JList list, SelectionField newf) {		//is an agg -- check and see if there are any non-aggs in the list	//if so, if we aren't grouping by them, ask the user what to do	//if user wants to remove them, do so	//otherwise, return false		ListModel model = list.getModel();	boolean hasAgg = hasAgg();	boolean newAgg = newf != null && newf.getOp() != null;		for (int i = 0; i < model.getSize(); i ++) {	    SelectionField sf = (SelectionField)model.getElementAt(i);	    boolean isGroupField = groupCheckBox.isSelected() && groupBox.getSelectedItem() == sf.getField();	    	    if (groupCheckBox.isSelected() && sf.getOp() == null && !isGroupField) {		setError("Can't group if a non-aggregate field is present");		return false;	    } else if (hasAgg && sf.getOp() == null && !isGroupField) {		setError("Can't have non-aggregate field when other aggregates are present");		return false;	    } else if ((!hasAgg && !isGroupField)  && (sf.getOp() != null || newAgg)) {		setError("Can't have aggregate field when non-aggregates are present");		return false;	    } else if (triggerCheckBox.isSelected() && sf.getOp() != null) {		setError("Can't enabled triggers when aggregates are present");		return false;	    } 	    	    //else if (hasAgg && newAgg) {	    //	    setError("Only one aggregate allow per query in current implementation.");	    //	    return false;	    //	}	}	if (triggerCheckBox.isSelected() && newAgg) {	    setError("Can't add aggregates when triggering");	    return false;	}	return true;    }        //check and see if there are any aggs in the selection list    public boolean hasAgg() {	ListModel model = selectDestList.getModel();	for (int i = 0; i < model.getSize(); i++) {	    SelectionField sf = (SelectionField)model.getElementAt(i);	    if (sf.getOp() != null) return true;	}	return false;    }        public void setError(String txt) {	sqlString.setText(txt);	setError = true;    }        /** Generate a SQL string for the current query */    public void updateSQL() {	String sql = "SELECT ";	boolean first = true;		if(setError) {	    setError = false;	    return;	}		ListModel model = selectDestList.getModel();		if (model.getSize() == 0) {	    sql = "Query must SELECT at least one attribute.";	} else {	    for (int i = 0; i < model.getSize(); i++) {		SelectionField sf = (SelectionField)model.getElementAt(i);		if (first) {		    sql += sf.toString();		    first = false;		}      else		    sql += ", " + sf.toString();	    }	    sql += " FROM sensors ";	    first = true;	    for (int i = 0; i < panels.length; i++) {		if (panels[i] != null) {		    if (first) {			sql += "\nWHERE " + panels[i].toString();			first = false;		    } else {			sql += " AND " + panels[i].toString();		    }		    		}	    }	    	    if (groupCheckBox.isSelected()) {		Integer atten = (Integer)attenuationBox.getSelectedItem();				sql += "\nGROUP BY " + groupBox.getSelectedItem().toString();				String groupByOp = (String) groupByOps.getSelectedItem();		if (!groupByOp.equals(""))		    sql += " " + groupByOp + " " + groupByConst.getText();		//if (atten.intValue() == 0) 		//    sql += groupBox.getSelectedItem().toString();		//else		//    sql += "(" + groupBox.getSelectedItem().toString() + ">>" + atten + ")";	    }	    	    sql += "\nSAMPLE PERIOD " + epochDur;	    	    if (triggerCheckBox.isSelected()) {		TriggerAction ta= (TriggerAction)triggerActionBox.getSelectedItem();				sql += "\nTRIGGER ACTION " + ta.command;				if (ta.hasParam)		    sql += "(" + ta.param +")";	    }	    	}	sqlString.setText(sql);	    }        /** Make sure the attribute selections are consistent with the grouping	information. */    void updateAttributeLists() {	ListModel srcModel = selectSrcList.getModel(), destModel = selectDestList.getModel();	Vector srcValues = new Vector(), destValues = new Vector();	String groupField = groupBox.getSelectedItem().toString();	String arithOp = (String) groupByOps.getSelectedItem();	String arithConst = null;	if (!arithOp.equals("")) {	    arithConst = groupByConst.getText();	} else {	    arithOp = null;	}	SelectionField cur;	int i;		// make sure groupField appears as "groupField op const" iff the group by box is checked	for (i = 0; i < srcModel.getSize(); i++) {

⌨️ 快捷键说明

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