/// <summary> /// Constructor. </summary> /// <param name="dataset"> the dataset in which the data are contained. </param> /// <param name="div"> the diversion to display. </param> /// <param name="editable"> whether the form data can be edited or not </param> public StateMod_Diversion_Right_JFrame(StateMod_DataSet dataset, StateMod_Diversion div, bool editable) { StateMod_GUIUtil.setTitle(this, dataset, div.getName() + " - Diversion Water Rights", null); JGUIUtil.setIcon(this, JGUIUtil.getIconImage()); __currentDiv = div; __dataset = dataset; __editable = editable; setupGUI(); }
/// <summary> /// Perform the query. Currently only diversion stations are supported. /// </summary> private void doQuery() { string routine = "StateMod_QueryTool_JFrame.doQuery", message; InputFilter_JPanel ifp = __input_filter_diversion_JPanel; InputFilter filter = null; int size; // Size of data Vector int i; // Loop for data items. DataSetComponent comp = null; string where, @operator, input; int where_length = 0; // Length of "where", to optimize code. bool do_int, do_double, do_string; string input_string; // Data parameters to check, as int input_int; // transferred from the data objects. double input_double; bool do_ID, do_Name, do_RiverNodeID, do_OnOff, do_Capacity, do_ReplaceResOption, do_DailyID, do_UserName, do_DemandType, do_EffAnnual, do_Area, do_UseType, do_DemandSource; bool[] matches = null; // Indicates if a data item matches all // the filter criteria. bool item_matches; // Indicates whether the itme matches a // single filter criteria. bool[] @checked = null; // Indicates whether a data item has // already been checked for a criteria. // If checked and false, then a "true" // should not reset the false. int nfg = 0; // Number of filter groups. do_int = false; // Whether the data item is an integer. do_double = false; // Whether the data item is a double. do_string = false; // Whether the data item is a string. StateMod_Diversion dds = null; __status_JTextField.setText(__Wait); JGUIUtil.setWaitCursor(this, true); if (ifp is StateMod_Diversion_InputFilter_JPanel) { input_int = StateMod_Util.MISSING_INT; input_double = StateMod_Util.MISSING_DOUBLE; input_string = StateMod_Util.MISSING_STRING; comp = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DIVERSION_STATIONS); //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Diversion> dds_Vector = (java.util.List<StateMod_Diversion>)comp.getData(); IList <StateMod_Diversion> dds_Vector = (IList <StateMod_Diversion>)comp.getData(); size = 0; if (dds_Vector != null) { size = dds_Vector.Count; } // REVISIT SAM 2004-10-27 Remove when debugging is complete //Message.printStatus ( 2, routine, //"Searching " + size + " diversion stations." ); // Initialize the arrays indicating if data objects have been // checked and whether they matched the filter(s)... if (size > 0) { matches = new bool[size]; @checked = new bool[size]; } for (i = 0; i < size; i++) { matches[i] = false; @checked[i] = false; } // Loop through the where clauses... nfg = ifp.getNumFilterGroups(); for (int ifg = 0; ifg < nfg; ifg++) { // Get the filter information... filter = ifp.getInputFilter(ifg); where = filter.getWhereInternal(); where_length = where.Length; @operator = ifp.getOperator(ifg); input = filter.getInput(false); // REVISIT SAM 2004-10-27 Remove when debugging is // complete //Message.printStatus ( 2, routine, //"where=" + where + " operator=" + operator + //" input=" + input ); // Initialize flags to indicate what data will be // checked... do_int = false; do_double = false; do_string = false; do_ID = false; do_Name = false; do_RiverNodeID = false; do_OnOff = false; do_Capacity = false; do_ReplaceResOption = false; do_DailyID = false; do_UserName = false; do_DemandType = false; do_EffAnnual = false; do_Area = false; do_UseType = false; do_DemandSource = false; // The following checks on "where" need to match the // input filter internal where labels assigned in // StateMod_Diversion_InputFilter_JPanel. // List in the order of the StateMod documentation... if (where.Equals("ID", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_ID = true; } else if (where.Equals("Name", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_Name = true; } else if (where.Equals("RiverNodeID", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_RiverNodeID = true; } else if (where.Equals("OnOff", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input)) { do_int = true; do_OnOff = true; } else if (where.Equals("Capacity", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input)) { do_double = true; do_Capacity = true; } else if (where.Equals("ReplaceResOption", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input)) { do_int = true; do_ReplaceResOption = true; } else if (where.Equals("DailyID", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_DailyID = true; } else if (where.Equals("UserName", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_UserName = true; } else if (where.Equals("DemandType", StringComparison.OrdinalIgnoreCase)) { do_int = true; do_DemandType = true; } else if (where.Equals("EffAnnual", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input)) { do_double = true; do_EffAnnual = true; } else if (where.Equals("Area", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input)) { do_double = true; do_Area = true; } else if (where.Equals("UseType", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input)) { do_int = true; do_UseType = true; } else if (where.Equals("DemandSource", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input)) { do_int = true; do_DemandSource = true; } else if (where_length == 0) { // WIll match anything. } else { // Unrecognized where... continue; } // REVISIT SAM 2004-10-27 Remove when debugging is // complete /* * Message.printStatus ( 2, routine, * "do_string=" + do_string + " do_int=" + do_int + * "do_double=" + do_double + * " " + do_ID + * " " + do_Name + * " " + do_RiverNodeID + * " " + do_OnOff + * " " + do_Capacity + * " " + do_ReplaceResOption + * " " + do_DailyID + * " " + do_UserName + * " " + do_DemandType + * " " + do_EffAnnual + * " " + do_Area + * " " + do_UseType + * " " + do_DemandSource ); */ for (i = 0; i < size; i++) { dds = (StateMod_Diversion)dds_Vector[i]; // Get the specific data to compare... if (do_ID) { input_string = dds.getID(); } else if (do_Name) { input_string = dds.getName(); } else if (do_RiverNodeID) { input_string = dds.getCgoto(); } else if (do_OnOff) { input_int = dds.getSwitch(); } else if (do_Capacity) { input_double = dds.getDivcap(); } else if (do_ReplaceResOption) { input_int = dds.getIreptype(); } else if (do_DailyID) { input_string = dds.getCdividy(); } else if (do_UserName) { input_string = dds.getUsername(); } else if (do_DemandType) { input_int = dds.getIdvcom(); } else if (do_EffAnnual) { input_double = dds.getDivefc(); } else if (do_Area) { input_double = dds.getArea(); } else if (do_UseType) { input_int = dds.getIrturn(); } else if (do_DemandSource) { input_int = dds.getDemsrc(); } else { // Unrecognized... continue; } // Compare the data with the input filter... item_matches = false; if (do_string) { item_matches = filter.matches(input_string, @operator, true); } else if (do_int) { item_matches = filter.matches(input_int, @operator); } else if (do_double) { item_matches = filter.matches(input_double, @operator); } if (where_length == 0) { // Always consider a match... item_matches = true; } if (item_matches && (!@checked[i] || (@checked[i] && matches[i]))) { // So far the item matches all // filters... matches[i] = true; } else if (@checked[i] && !item_matches) { // Does not match this filter to reset // result to false... matches[i] = false; } // Indicate that we have checked the item // against at least one filter... @checked[i] = true; } } // Get a count so the Vector can be sized appropriately (this // should be fast)... int match_count = 0; for (i = 0; i < size; i++) { if (matches[i]) { ++match_count; } } // Loop through and set up the matches_Vector... __matches_Vector = null; if (match_count > 0) { __matches_Vector = new List <StateMod_Diversion> (match_count); for (i = 0; i < size; i++) { if (matches[i]) { // The diversion station matches so add // to the list... __matches_Vector.Add(dds_Vector[i]); } } } message = "Matched " + match_count + " diversion stations (from original " + size + ")."; Message.printStatus(2, routine, message); __message_JTextField.setText(message); __status_JTextField.setText(__Ready); JGUIUtil.setWaitCursor(this, false); } if (__matches_Vector == null) { __display_JButton.setEnabled(false); } else { __display_JButton.setEnabled(true); } }
/// <summary> /// Returns the data that should be placed in the JTable at the given row and /// column. </summary> /// <param name="row"> the row for which to return data. </param> /// <param name="col"> the column for which to return data. </param> /// <returns> the data that should be placed in the JTable at the given row and col. </returns> public virtual object getValueAt(int row, int col) { if (_sortOrder != null) { row = _sortOrder[row]; } StateMod_Diversion smd = (StateMod_Diversion)_data.get(row); switch (col) { case COL_ID: return(smd.getID()); case COL_NAME: return(smd.getName()); case COL_RIVER_NODE_ID: return(smd.getCgoto()); case COL_ON_OFF: return(new int?(smd.getSwitch())); case COL_CAPACITY: return(new double?(smd.getDivcap())); case COL_REPLACE_RES_OPTION: return(new int?(smd.getIreptype())); case COL_DAILY_ID: return(smd.getCdividy()); case COL_USER_NAME: return(smd.getUsername()); case COL_DEMAND_TYPE: return(new int?(smd.getIdvcom())); case COL_AREA: return(new double?(smd.getArea())); case COL_USE_TYPE: return(new int?(smd.getIrturn())); case COL_DEMAND_SOURCE: return(new int?(smd.getDemsrc())); case COL_EFF_ANNUAL: return(new double?(smd.getDivefc())); case COL_EFF_01: return(new double?(smd.getDiveff(0))); case COL_EFF_02: return(new double?(smd.getDiveff(1))); case COL_EFF_03: return(new double?(smd.getDiveff(2))); case COL_EFF_04: return(new double?(smd.getDiveff(3))); case COL_EFF_05: return(new double?(smd.getDiveff(4))); case COL_EFF_06: return(new double?(smd.getDiveff(5))); case COL_EFF_07: return(new double?(smd.getDiveff(6))); case COL_EFF_08: return(new double?(smd.getDiveff(7))); case COL_EFF_09: return(new double?(smd.getDiveff(8))); case COL_EFF_10: return(new double?(smd.getDiveff(9))); case COL_EFF_11: return(new double?(smd.getDiveff(10))); case COL_EFF_12: return(new double?(smd.getDiveff(11))); default: return(""); } }
/// <summary> /// Sets up the GUI. /// </summary> public virtual void setupGUI() { string routine = "setupGUI"; addWindowListener(this); __addReturnFlow = new JButton(__BUTTON_ADD_RETURN_FLOW); __deleteReturnFlow = new JButton(__BUTTON_DEL_RETURN_FLOW); __helpJButton = new JButton(__BUTTON_HELP); __helpJButton.setEnabled(false); __closeJButton = new JButton(__BUTTON_CLOSE); JButton cancelJButton = new JButton(__BUTTON_CANCEL); JButton applyJButton = new JButton(__BUTTON_APPLY); GridBagLayout gb = new GridBagLayout(); JPanel bigPanel = new JPanel(); bigPanel.setLayout(gb); JPanel p1 = new JPanel(); p1.setLayout(new FlowLayout(FlowLayout.RIGHT)); GridLayout gl = new GridLayout(2, 2, 1, 1); JPanel info_panel = new JPanel(); info_panel.setLayout(gl); JPanel main_panel = new JPanel(); main_panel.setLayout(new BorderLayout()); info_panel.add(new JLabel("Diversion:")); info_panel.add(new JLabel(__currentDiv.getID())); info_panel.add(new JLabel("Diversion name:")); info_panel.add(new JLabel(__currentDiv.getName())); if (__editable) { p1.add(__addReturnFlow); p1.add(__deleteReturnFlow); __deleteReturnFlow.setEnabled(false); } // p1.add(__helpJButton); p1.add(applyJButton); p1.add(cancelJButton); p1.add(__closeJButton); PropList p = new PropList("StateMod_Diversion_ReturnFlow_JFrame" + ".JWorksheet"); p.add("JWorksheet.ShowPopupMenu=true"); p.add("JWorksheet.AllowCopy=true"); p.add("JWorksheet.SelectionMode=SingleRowSelection"); int[] widths = null; JScrollWorksheet jsw = null; try { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_RiverNetworkNode> nodes = (java.util.List <StateMod_RiverNetworkNode>)(__dataset.getComponentForComponentType(StateMod_DataSet.COMP_RIVER_NETWORK).getData()); IList <StateMod_RiverNetworkNode> nodes = (IList <StateMod_RiverNetworkNode>)(__dataset.getComponentForComponentType(StateMod_DataSet.COMP_RIVER_NETWORK).getData()); IList <StateMod_ReturnFlow> v = new List <StateMod_ReturnFlow>(); IList <StateMod_ReturnFlow> v2 = __currentDiv.getReturnFlows(); int size = v2.Count; StateMod_ReturnFlow rf; for (int i = 0; i < size; i++) { rf = (StateMod_ReturnFlow)v2[i].clone(); rf.setCrtnid(rf.getCrtnid() + StateMod_Util.findNameInVector(rf.getCrtnid(), nodes, true)); v.Add(rf); } StateMod_ReturnFlow_TableModel tmd = new StateMod_ReturnFlow_TableModel(__dataset, v, __editable, true); StateMod_ReturnFlow_CellRenderer crd = new StateMod_ReturnFlow_CellRenderer(tmd); jsw = new JScrollWorksheet(crd, tmd, p); __worksheet = jsw.getJWorksheet(); // TODO SAM 2017-03-15 something not right here - looks like original list variable was wrong //v = StateMod_Util.createIdentifierListFromStateModData(nodes, true, null); __worksheet.setColumnJComboBoxValues(StateMod_ReturnFlow_TableModel.COL_RIVER_NODE, v, false); // 10 System.Collections.IList delayIDs = null; if (__dataset.getIday() == 1) { delayIDs = (System.Collections.IList)(__dataset.getComponentForComponentType(StateMod_DataSet.COMP_DELAY_TABLES_DAILY).getData()); } else { delayIDs = (System.Collections.IList)(__dataset.getComponentForComponentType(StateMod_DataSet.COMP_DELAY_TABLES_MONTHLY).getData()); } v = StateMod_Util.createIdentifierListFromStateModData(delayIDs, true, null); __worksheet.setColumnJComboBoxValues(StateMod_ReturnFlow_TableModel.COL_RETURN_ID, v, false); widths = crd.getColumnWidths(); } catch (Exception e) { Message.printWarning(2, routine, e); jsw = new JScrollWorksheet(0, 0, p); __worksheet = jsw.getJWorksheet(); } __worksheet.setPreferredScrollableViewportSize(null); __worksheet.setHourglassJFrame(this); __worksheet.addMouseListener(this); __worksheet.addKeyListener(this); main_panel.add(jsw, "Center"); main_panel.add(p1, "South"); JGUIUtil.addComponent(bigPanel, info_panel, 0, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); JGUIUtil.addComponent(bigPanel, main_panel, 0, 1, 10, 10, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.SOUTH); __addReturnFlow.addActionListener(this); __deleteReturnFlow.addActionListener(this); __closeJButton.addActionListener(this); __helpJButton.addActionListener(this); cancelJButton.addActionListener(this); applyJButton.addActionListener(this); getContentPane().add(bigPanel); JPanel bottomJPanel = new JPanel(); bottomJPanel.setLayout(gb); __messageJTextField = new JTextField(); __messageJTextField.setEditable(false); JGUIUtil.addComponent(bottomJPanel, __messageJTextField, 0, 0, 7, 1, 1.0, 0.0, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); __statusJTextField = new JTextField(5); __statusJTextField.setEditable(false); JGUIUtil.addComponent(bottomJPanel, __statusJTextField, 7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NONE, GridBagConstraints.WEST); getContentPane().add("South", bottomJPanel); pack(); setSize(530, 280); JGUIUtil.center(this); setVisible(true); if (widths != null) { __worksheet.setColumnWidths(widths); } }
/// <summary> /// Sets up the GUI. /// </summary> private void setupGUI() { string routine = "setupGUI"; addWindowListener(this); __addRight = new JButton(__BUTTON_ADD_RIGHT); __deleteRight = new JButton(__BUTTON_DEL_RIGHT); __closeJButton = new JButton(__BUTTON_CLOSE); __helpJButton = new JButton(__BUTTON_HELP); JButton cancelJButton = new JButton(__BUTTON_CANCEL); JButton applyJButton = new JButton(__BUTTON_APPLY); __helpJButton.setEnabled(false); GridBagLayout gbl = new GridBagLayout(); JPanel bigPanel = new JPanel(); bigPanel.setLayout(gbl); JPanel p1 = new JPanel(); p1.setLayout(new FlowLayout(FlowLayout.RIGHT)); GridLayout gl = new GridLayout(2, 2, 1, 1); JPanel info_panel = new JPanel(); info_panel.setLayout(gl); JPanel main_panel = new JPanel(); main_panel.setLayout(new BorderLayout()); info_panel.add(new JLabel("Diversion ID: ")); info_panel.add(new JLabel(__currentDiv.getID())); info_panel.add(new JLabel("Diversion name: ")); info_panel.add(new JLabel(__currentDiv.getName())); if (__editable) { p1.add(__addRight); p1.add(__deleteRight); __deleteRight.setEnabled(false); } //p1.add(__helpJButton); p1.add(applyJButton); p1.add(cancelJButton); p1.add(__closeJButton); PropList p = new PropList("StateMod_Diversion_Right_JFrame" + ".JWorksheet"); p.add("JWorksheet.ShowPopupMenu=true"); p.add("JWorksheet.AllowCopy=true"); p.add("JWorksheet.SelectionMode=SingleRowSelection"); int[] widths = null; JScrollWorksheet jsw = null; try { System.Collections.IList v = new List <object>(); System.Collections.IList v2 = __currentDiv.getRights(); for (int i = 0; i < v2.Count; i++) { v.Add(((StateMod_DiversionRight)(v2[i])).clone()); } StateMod_DiversionRight_TableModel tmd = new StateMod_DiversionRight_TableModel(v, __editable, false); StateMod_DiversionRight_CellRenderer crd = new StateMod_DiversionRight_CellRenderer(tmd); jsw = new JScrollWorksheet(crd, tmd, p); __worksheet = jsw.getJWorksheet(); widths = crd.getColumnWidths(); } catch (Exception e) { Message.printWarning(1, routine, "Error building worksheet."); Message.printWarning(2, routine, e); jsw = new JScrollWorksheet(0, 0, p); __worksheet = jsw.getJWorksheet(); } __worksheet.setPreferredScrollableViewportSize(null); __worksheet.setHourglassJFrame(this); __worksheet.addMouseListener(this); __worksheet.addKeyListener(this); System.Collections.IList v = new List <object>(); v.Add("0 - Off"); v.Add("1 - On"); __worksheet.setColumnJComboBoxValues(StateMod_DiversionRight_TableModel.COL_ON_OFF, v); main_panel.add(jsw, "Center"); main_panel.add(p1, "South"); JGUIUtil.addComponent(bigPanel, info_panel, 0, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); JGUIUtil.addComponent(bigPanel, main_panel, 0, 1, 10, 10, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.SOUTH); getContentPane().add(bigPanel); JPanel bottomJPanel = new JPanel(); bottomJPanel.setLayout(gbl); __messageJTextField = new JTextField(); __messageJTextField.setEditable(false); JGUIUtil.addComponent(bottomJPanel, __messageJTextField, 0, 0, 7, 1, 1.0, 0.0, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); __statusJTextField = new JTextField(5); __statusJTextField.setEditable(false); JGUIUtil.addComponent(bottomJPanel, __statusJTextField, 7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NONE, GridBagConstraints.WEST); getContentPane().add("South", bottomJPanel); __addRight.addActionListener(this); __deleteRight.addActionListener(this); __closeJButton.addActionListener(this); __helpJButton.addActionListener(this); cancelJButton.addActionListener(this); applyJButton.addActionListener(this); pack(); setSize(600, 450); JGUIUtil.center(this); setVisible(true); if (widths != null) { __worksheet.setColumnWidths(widths); } }