📄 guipanel.java
字号:
cur = (SelectionField) srcModel.getElementAt(i); if (cur.equals(groupField)) { if (groupCheckBox.isSelected()) { cur.setArithOp(arithOp); cur.setArithConst(arithConst); } } srcValues.addElement(cur); } selectSrcList.setListData(srcValues); for (i = 0; i < destModel.getSize(); i++) { cur = (SelectionField) destModel.getElementAt(i); if (cur.equals(groupField)) { if (groupCheckBox.isSelected()) { cur.setArithOp(arithOp); cur.setArithConst(arithConst); } } destValues.addElement(cur); } selectDestList.setListData(destValues); } /** Generate a TinyDBQuery to represent the currently selected query fields */ TinyDBQuery generateQuery(byte queryId, short epochDur) { ListModel model = selectDestList.getModel(); if (model.getSize() == 0) return null; if (!checkSelectionConsistency(selectDestList, null)) return null; if (TinyDBMain.debug) System.out.println("Running query: " + sqlString.getText()); if (TinyDBMain.debug) System.out.println("Query ID = " + queryId); TinyDBQuery query = null; try { query = SensorQueryer.translateQuery(sqlString.getText(), queryId); } catch (ParseException pe) { System.err.println(pe.getMessage()); if (TinyDBMain.debug) { pe.printStackTrace(); System.err.println(pe.getParseError()); } } return (query); } /** CatalogListener method called when a new attribute gets added */ public void addedAttr(QueryField qf) { System.out.println("NEW ATTRIBUTE: " + qf); Vector values = new Vector(); ListModel model = selectSrcList.getModel(); for (int i = 0; i < model.getSize(); i++) { if (!((QueryField)model.getElementAt(i)).getName().equals(qf.getName())) values.addElement(model.getElementAt(i)); } values.addElement(qf); selectSrcList.setListData(values); } private int numSelects = 0; public static boolean topologyWindowUp = false; private MainClass topologyFrame; private JList selectDestList; private JPanel groupByPanel; private JButton removeSelButton; private JSeparator jSeparator2; private JPanel selectGroupPanel; private JLabel groupLabel; private JButton newPredButton; private JComboBox groupBox; private JComboBox epochBox; private JComboBox attenuationBox; private JComboBox aggregateBox; private JLabel selectedLabel; private JButton addSelButton; private JLabel selectFieldsLabel; private JTextArea sqlString; private JList selectSrcList; private JCheckBox groupCheckBox; private JComboBox groupByOps; private JTextField groupByConst; private JCheckBox logCheckBox; private JPanel triggerPanel; private JLabel triggerLabel; private JCheckBox triggerCheckBox; private JComboBox triggerActionBox; private TriggerAction triggerActions[] = {new TriggerAction("Toggle Red Led", "SetLedR", true, (short)0x0202), new TriggerAction("Toggle Yellow Led", "SetLedY", true, (short)0x0202), new TriggerAction("Toggle Green Led", "SetLedG", true, (short)0x0202), new TriggerAction("Sounder (100ms)", "SetSnd", true, (short)100), new TriggerAction("Sounder (500ms)", "SetSnd", true, (short)500), new TriggerAction("Sounder (1000ms)", "SetSnd", true, (short)1000)}; private SelOp eq = new SelOp(SelOp.OP_EQ); private SelOp neq = new SelOp(SelOp.OP_NEQ); private SelOp gt = new SelOp(SelOp.OP_GT); private SelOp ge = new SelOp(SelOp.OP_GE); private SelOp lt = new SelOp(SelOp.OP_LT); private SelOp le = new SelOp(SelOp.OP_LE); private AggOp min = new AggOp(AggOp.AGG_MIN); private AggOp max = new AggOp(AggOp.AGG_MAX); private AggOp sum = new AggOp(AggOp.AGG_SUM); private AggOp avg = new AggOp(AggOp.AGG_AVERAGE); private AggOp cnt = new AggOp(AggOp.AGG_COUNT); private String arithOps[] = {"","+","-","*","/","%",">>"}; private SelOp ops[] = {eq,neq,gt,ge,lt,le}; private AggOp aggs[] = {null, min,max,sum,avg,cnt}; private Integer attens[] = {new Integer(0), new Integer(1), new Integer(2), new Integer(3), new Integer(4), new Integer(5), new Integer(6), new Integer(7), new Integer(8), new Integer(9), new Integer(10)}; int numPanels = 0; WherePanel panels[] = new WherePanel[3]; boolean setError = false; Object oldGroup; short epochDur = 1024; Vector resultWins = new Vector(); boolean sendingQuery = false; boolean logQueryToDB = true; TinyDBNetwork nw; private Font normalFont = Font.decode("dialog-18"); private Font textBoxFont = Font.decode("serif-16"); private Font boldFont = Font.decode("dialog-bold-18"); private Font bigFont = Font.decode("dialog-bold-18"); private Font underlineFont = Font.decode("dialog-underline");}class SelectionField { public SelectionField(AggOp op, QueryField field) { this.op = op; this.field = field; } public AggOp getOp() { return op; } public QueryField getField() { return field; } public String toString() { if (op == null) return field.toString(); else return op.toString() + "(" + field.toString() + ")"; } public void setArithOp(String arithOp) { this.arithOp = arithOp; } public void setArithConst(String arithConst) { this.arithConst = arithConst; } String arithOp = null, arithConst = null; AggOp op; QueryField field;}class WherePanel extends JPanel { static final int BUT_SEP = 10; static final int ATTR_POPUP_WID = 120; static final int FIELD_OP_BOX_WID = 60; static final int FIELD_CONST_WID = 60; static final int WHERE_LABEL_LEFT = 30; static final int BUT_HEIGHT = 30; static final int WHERE_WID = 60; static final int WHERE_ATTR_LEFT = WHERE_LABEL_LEFT + WHERE_WID + BUT_SEP; static final int FIELD_OP_BOX_LEFT = WHERE_ATTR_LEFT + ATTR_POPUP_WID; static final int FIELD_CONST_LEFT = FIELD_OP_BOX_LEFT + FIELD_OP_BOX_WID; static final int OP_BOX_LEFT = FIELD_CONST_LEFT + FIELD_CONST_WID; static final int OP_BOX_WIDTH = 60; static final int CONSTANT_BOX_LEFT = OP_BOX_LEFT + OP_BOX_WIDTH; static final int CONSTANT_BOX_WID = 60; static final int SELECT_PANEL_WID = CONSTANT_BOX_LEFT + CONSTANT_BOX_WID; static final int RMV_WHERE_WID = 50; //build a selection panel public WherePanel(int panelId, final GuiPanel parent) { this.panelId = panelId; this.parent = parent; constantField = new JTextField(); innerPanel = new JPanel(); whereLabel = new JLabel(); attributeBox = new JComboBox(); attributeBox.setLightWeightPopupEnabled(false); parent.addFieldsToMenu(attributeBox); fieldOpBox = new JComboBox(); fieldOpBox.setLightWeightPopupEnabled(false); parent.addArithOpsToMenu(fieldOpBox); fieldOpBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JComboBox cb = (JComboBox)evt.getSource(); String op = (String)cb.getSelectedItem(); if (!op.equals("")) { fieldConst.setEnabled(true); } else { fieldConst.setEnabled(false); } parent.updateSQL(); } }); fieldConst = new JTextField(); fieldConst.setEnabled(false); fieldConst.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e){ parent.updateSQL(); } public void insertUpdate(DocumentEvent e){ parent.updateSQL(); } public void removeUpdate(DocumentEvent e){ parent.updateSQL(); } }); opBox = new JComboBox(); opBox.setLightWeightPopupEnabled(false); parent.addOpsToMenu(opBox); removeWhereButton = new JButton(); setLayout(new AbsoluteLayout()); // setBackground(java.awt.Color.white); innerPanel.setLayout(new AbsoluteLayout()); // innerPanel.setBackground(java.awt.Color.white); whereLabel.setHorizontalAlignment(SwingConstants.CENTER); whereLabel.setText("WHERE"); innerPanel.add(whereLabel, new AbsoluteConstraints(WHERE_LABEL_LEFT, 5, -1, -1)); innerPanel.add(attributeBox, new AbsoluteConstraints(WHERE_ATTR_LEFT, 0, ATTR_POPUP_WID, BUT_HEIGHT)); attributeBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { parent.updateSQL(); } }); innerPanel.add(fieldOpBox, new AbsoluteConstraints(FIELD_OP_BOX_LEFT, 0, FIELD_OP_BOX_WID, BUT_HEIGHT)); innerPanel.add(fieldConst, new AbsoluteConstraints(FIELD_CONST_LEFT, 0, FIELD_CONST_WID, BUT_HEIGHT)); innerPanel.add(opBox, new AbsoluteConstraints(OP_BOX_LEFT, 0, OP_BOX_WIDTH, BUT_HEIGHT)); opBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { parent.updateSQL(); } }); constantField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e){ parent.updateSQL(); } public void insertUpdate(DocumentEvent e){ parent.updateSQL(); } public void removeUpdate(DocumentEvent e){ parent.updateSQL(); } }); innerPanel.add(constantField, new AbsoluteConstraints(CONSTANT_BOX_LEFT, 0, CONSTANT_BOX_WID, BUT_HEIGHT)); add(innerPanel, new AbsoluteConstraints(0, 0, SELECT_PANEL_WID, BUT_HEIGHT)); removeWhereButton.setText("-"); removeWhereButton.setToolTipText("Delete This Predicate"); removeWhereButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { removeWhereButton(evt); } }); add(removeWhereButton, new AbsoluteConstraints(SELECT_PANEL_WID, 0, RMV_WHERE_WID, BUT_HEIGHT)); } private void removeWhereButton(ActionEvent evt) { parent.removeWhereButtonActionPerformed(evt,this.panelId); } private void constantFieldActionPerformed(ActionEvent evt) { } public String toString() { String str = ""; str += attributeBox.getSelectedItem().toString() + " "; if (!getFieldOp().equals("")) str += getFieldOp() + " " + getFieldConst() + " "; str += opBox.getSelectedItem().toString() + " " + constantField.getText(); return str; } public String getFieldConst() { return fieldConst.getText(); } public String getFieldOp() { return ((String) fieldOpBox.getSelectedItem()); } public QueryField getField() { return (QueryField)attributeBox.getSelectedItem(); } public SelOp getOp() { return (SelOp)opBox.getSelectedItem(); } public short getConstant() throws NumberFormatException { Short constant = new Short(constantField.getText()); return constant.shortValue(); } public void setId(int id) { panelId = id; } public int getId() { return panelId; } JPanel innerPanel; JLabel whereLabel; JComboBox opBox; JComboBox attributeBox; JTextField constantField; JButton removeWhereButton; JComboBox fieldOpBox; JTextField fieldConst; int panelId; final GuiPanel parent;}class TriggerAction { public String name; public String command; public boolean hasParam = false; public short param; public TriggerAction(String name, String command, boolean hasParam, short param) { this.name = name; this.command = command; this.hasParam = hasParam; this.param = param; } public String toString() { return name; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -