/// <summary> /// Checks to see if the mouse event would trigger display of the popup menu. /// The popup menu does not display if it is null. </summary> /// <param name="e"> the MouseEvent that happened. </param> private void showPopupMenu(MouseEvent e) { string routine = "StateMod_DataSet_JTree.showPopupMenu"; if (!e.isPopupTrigger() || !__display_data_objects) { // Do not do anything... return; } TreePath path = getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } __popup_Node = (SimpleJTree_Node)path.getLastPathComponent(); // First remove the menu items that are currently in the menu... __popup_JPopupMenu.removeAll(); object data = null; // Data object associated with the node DataSetComponent comp2; // Used to check components in groups. // Now reset the popup menu based on the selected node... if (__display_data_objects) { // Get the data for the node. If the node is a data object, // the type can be checked to know what to display. // The tree is displaying data objects so the popup will show // specific JFrames for each data group. If the group folder // was selected, then display the JFrame showing the first item // selected. If a specific data item in the group was selected, // then show the specific data item. JMenuItem item; data = __popup_Node.getData(); if (data is DataSetComponent) { // Specific checks need to be done to identify the component group... DataSetComponent comp = (DataSetComponent)data; int comp_type = comp.getComponentType(); if (comp_type == StateMod_DataSet.COMP_CONTROL_GROUP) { // For now display the control file information only... comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_CONTROL); if (comp2.hasData()) { item = new SimpleJMenuItem("Control Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_STREAMGAGE_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_STREAMGAGE_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Stream Gage Station Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_DELAY_TABLE_MONTHLY_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DELAY_TABLES_MONTHLY); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Delay Table Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_DELAY_TABLE_DAILY_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DELAY_TABLES_MONTHLY); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Delay Table Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_DIVERSION_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DIVERSION_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Diversion Properties", this); __popup_JPopupMenu.add(item); } } else if ((comp_type == StateMod_DataSet.COMP_PRECIPITATION_GROUP)) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_PRECIPITATION_TS_MONTHLY); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Precipitation Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_EVAPORATION_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_EVAPORATION_TS_MONTHLY); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Evaporation Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_RESERVOIR_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_RESERVOIR_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Reservoir Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_INSTREAM_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_INSTREAM_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Instream Flow Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_WELL_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_WELL_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Well Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_PLAN_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_PLANS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Plan Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_STREAMESTIMATE_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_STREAMESTIMATE_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Stream Estimate Station Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_RIVER_NETWORK_GROUP) { // Only add if data are available... comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_RIVER_NETWORK); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("River Network Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_OPERATION_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_OPERATION_RIGHTS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Operation Rights Properties", this); __popup_JPopupMenu.add(item); } } } // The data are a specific data instance so display the // properties for the specific item if a primary data item. // Control... nothing for now. else if (data is StateMod_StreamGage) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_DelayTable) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_Diversion) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); __popup_JPopupMenu.add(new SimpleJMenuItem(__SUMMARIZE_HOW1 + "\"" + __popup_Node.getText() + "\"" + __SUMMARIZE_HOW2, this)); } else if (data is MonthTS) { // Precipitation or evaporation time series... __popup_JPopupMenu.add(new SimpleJMenuItem(__popup_Node.getText() + __PROPERTIES, this)); __popup_JPopupMenu.add(new SimpleJMenuItem(__SUMMARIZE_HOW1 + "\"" + __popup_Node.getText() + "\"" + __SUMMARIZE_HOW2, this)); } else if (data is StateMod_Reservoir) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_InstreamFlow) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_Well) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_Plan) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_StreamEstimate) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_OperationalRight) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_RiverNetworkNode) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } // Others (e.g., San Juan Sediment) supported later.... else { Message.printWarning(2, routine, "Node data is not recognized"); return; } } // Now display the popup so that the user can select the appropriate menu item... Point pt = JGUIUtil.computeOptimalPosition(e.getPoint(), e.getComponent(), __popup_JPopupMenu); __popup_JPopupMenu.show(e.getComponent(), pt.x, pt.y); }
/// <summary> /// Checks to see if the mouse event would trigger display of the popup menu. /// The popup menu does not display if it is null. </summary> /// <param name="e"> the MouseEvent that happened. </param> private void showPopupMenu(MouseEvent e) { if (!e.isPopupTrigger() || !__display_data_objects) { // Do not do anything... return; } // Figure out which node is selected... TreePath path = getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } __popup_Node = (SimpleJTree_Node)path.getLastPathComponent(); // First remove the menu items that are currently in the menu... __popup_JPopupMenu.removeAll(); object data = null; // Data object associated with the node // Now reset the popup menu based on the selected node... if (__display_data_objects) { // Get the data for the node. If the node is a data object, // the type can be checked to know what to display. // The tree is displaying data objects so the popup will show // specific JFrames for each data group. If the group folder // was selected, then display the JFrame showing the first item // selected. If a specific data item in the group was selected, // then show the specific data item. JMenuItem item; data = __popup_Node.getData(); if (data is DataSetComponent) { // Specific checks need to be done to identify the // component... DataSetComponent comp = (DataSetComponent)data; int comp_type = comp.getComponentType(); if (comp_type == StateCU_DataSet.COMP_CLIMATE_STATIONS_GROUP) { item = new SimpleJMenuItem("Climate Stations Properties", "Climate Stations Properties", this); __popup_JPopupMenu.add(item); } else if (comp_type == StateCU_DataSet.COMP_CROP_CHARACTERISTICS_GROUP) { item = new SimpleJMenuItem("Crop Properties", "Crop Properties", this); __popup_JPopupMenu.add(item); } else if (comp_type == StateCU_DataSet.COMP_DELAY_TABLES_GROUP) { item = new SimpleJMenuItem("Delay Tables Properties", "Delay Tables Properties", this); __popup_JPopupMenu.add(item); } else if (comp_type == StateCU_DataSet.COMP_CU_LOCATIONS_GROUP) { item = new SimpleJMenuItem("CU Locations Properties", "CU Locations Properties", this); __popup_JPopupMenu.add(item); } } // Check specific instances of the primary data object... else if (data is StateCU_ClimateStation) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", __popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateCU_CropCharacteristics) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", __popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_DelayTable) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", __popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateCU_Location) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", __popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else { return; } } // Now display the popup so that the user can select the appropriate // menu item... __popup_JPopupMenu.show(e.getComponent(), e.getX(), e.getY()); }
/// <summary> /// Responds to action performed events sent by popup menus of the tree nodes. </summary> /// <param name="event"> the ActionEvent that happened. </param> public virtual void actionPerformed(ActionEvent @event) { string action = @event.getActionCommand(); string routine = "StateMod_DataSet_JTree.actionPerformed"; object data = __popup_Node.getData(); if (data is DataSetComponent) { DataSetComponent comp = (DataSetComponent)data; int comp_type = comp.getComponentType(); if (comp_type == StateMod_DataSet.COMP_CONTROL_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_CONTROL, __editable); } else if (comp_type == StateMod_DataSet.COMP_STREAMGAGE_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_STREAMGAGE, __editable); } else if (comp_type == StateMod_DataSet.COMP_DELAY_TABLE_MONTHLY_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_DELAY_TABLE_MONTHLY, __editable); } else if (comp_type == StateMod_DataSet.COMP_DELAY_TABLE_DAILY_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_DELAY_TABLE_DAILY, __editable); } else if (comp_type == StateMod_DataSet.COMP_DIVERSION_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_DIVERSION, __editable); } else if (comp_type == StateMod_DataSet.COMP_PRECIPITATION_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_PRECIPITATION, __editable); } else if (comp_type == StateMod_DataSet.COMP_EVAPORATION_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_EVAPORATION, __editable); } else if (comp_type == StateMod_DataSet.COMP_RESERVOIR_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_RESERVOIR, __editable); } else if (comp_type == StateMod_DataSet.COMP_INSTREAM_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_INSTREAM, __editable); } else if (comp_type == StateMod_DataSet.COMP_WELL_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_WELL, __editable); } else if (comp_type == StateMod_DataSet.COMP_PLAN_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_PLAN, __editable); } else if (comp_type == StateMod_DataSet.COMP_STREAMESTIMATE_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_STREAMESTIMATE, __editable); } else if (comp_type == StateMod_DataSet.COMP_RIVER_NETWORK_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_RIVER_NETWORK, __editable); } else if (comp_type == StateMod_DataSet.COMP_OPERATION_GROUP) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_OPERATIONAL_RIGHT, __editable); } } // Below here are specific instances of objects. Similar to above, // display the main window but then also select the specific object... else if (data is StateMod_StreamGage) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_STREAMGAGE, __editable); ((StateMod_StreamGage_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_STREAMGAGE)).selectID(((StateMod_StreamGage)data).getID()); } else if (data is StateMod_DelayTable) { StateMod_DelayTable dt = (StateMod_DelayTable)data; if (dt.isMonthly()) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_DELAY_TABLE_MONTHLY, __editable); ((StateMod_DelayTable_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_DELAY_TABLE_MONTHLY)).selectID(dt.getID()); } else { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_DELAY_TABLE_DAILY, __editable); ((StateMod_DelayTable_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_DELAY_TABLE_DAILY)).selectID(dt.getID()); } } else if (data is StateMod_Diversion) { if (action.IndexOf(__SUMMARIZE_HOW1, StringComparison.Ordinal) >= 0) { PropList props = new PropList("Diversion"); props.set("Title=" + ((StateMod_Diversion)data).getID() + " Diversion use in Data Set"); new ReportJFrame(__dataset.getDataObjectDetails(StateMod_DataSet.COMP_DIVERSION_STATIONS, ((StateMod_Diversion)data).getID()), props); } else { // Assume properties... __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_DIVERSION, __editable); ((StateMod_Diversion_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_DIVERSION)).selectID(((StateMod_Diversion)data).getID()); } } else if (data is TS) { // Might be precipitation or evaporation. Check the data type to determine... TS ts = (TS)data; PropList props = new PropList("Precipitation/Evaporation"); if (action.IndexOf(__SUMMARIZE_HOW1, StringComparison.Ordinal) >= 0) { if (StringUtil.startsWithIgnoreCase(ts.getDataType(), "e")) { props.set("Title=" + ts.getLocation() + " Evaporation TS use in Data Set"); new ReportJFrame(__dataset.getDataObjectDetails(StateMod_DataSet.COMP_EVAPORATION_TS_MONTHLY, ts.getLocation()), props); } else if (StringUtil.startsWithIgnoreCase(ts.getDataType(), "p")) { props.set("Title=" + ts.getLocation() + " Precipitation TS use in Data Set"); new ReportJFrame(__dataset.getDataObjectDetails(StateMod_DataSet.COMP_PRECIPITATION_TS_MONTHLY, ts.getLocation()), props); } } else if (action.IndexOf(__PROPERTIES, StringComparison.Ordinal) >= 0) { if (StringUtil.startsWithIgnoreCase(ts.getDataType(), "e")) { props.set("Title=Evaporation"); } else if (StringUtil.startsWithIgnoreCase(ts.getDataType(), "p")) { props.set("Title=Precipitation"); } props.set("InitialView=Graph"); props.set("GraphType=Bar"); System.Collections.IList tslist = new List <object>(1); tslist.Add(ts); try { new TSViewJFrame(tslist, props); } catch (Exception) { Message.printWarning(1, routine, "Error displaying data."); } } } else if (data is StateMod_Reservoir) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_RESERVOIR, __editable); ((StateMod_Reservoir_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_RESERVOIR)).selectID(((StateMod_Reservoir)data).getID()); } else if (data is StateMod_InstreamFlow) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_INSTREAM, __editable); ((StateMod_InstreamFlow_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_INSTREAM)).selectID(((StateMod_InstreamFlow)data).getID()); } else if (data is StateMod_Well) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_WELL, __editable); ((StateMod_Well_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_WELL)).selectID(((StateMod_Well)data).getID()); } else if (data is StateMod_Plan) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_PLAN, __editable); ((StateMod_Plan_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_PLAN)).selectID(((StateMod_Plan)data).getID()); } else if (data is StateMod_StreamEstimate) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_STREAMESTIMATE, __editable); ((StateMod_StreamEstimate_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_STREAMESTIMATE)).selectID(((StateMod_StreamEstimate)data).getID()); } else if (data is StateMod_RiverNetworkNode) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_RIVER_NETWORK, __editable); ((StateMod_RiverNetworkNode_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_RIVER_NETWORK)).selectID(((StateMod_RiverNetworkNode)data).getID()); } else if (data is StateMod_OperationalRight) { __dataset_wm.displayWindow(StateMod_DataSet_WindowManager.WINDOW_OPERATIONAL_RIGHT, __editable); ((StateMod_OperationalRight_JFrame)__dataset_wm.getWindow(StateMod_DataSet_WindowManager.WINDOW_OPERATIONAL_RIGHT)).selectID(((StateMod_OperationalRight)data).getID()); } }
/// <summary> /// Handle action events from the popup menu. </summary> /// <param name="e"> ActionEvent to handle. </param> public virtual void actionPerformed(ActionEvent e) { object data = __popup_Node.getData(); bool editable = false; if (data is DataSetComponent) { DataSetComponent comp = (DataSetComponent)data; int comp_type = comp.getComponentType(); if (comp_type == StateCU_DataSet.COMP_CLIMATE_STATIONS_GROUP) { new StateCU_ClimateStation_JFrame("Climate Stations", __dataset, editable); } else if (comp_type == StateCU_DataSet.COMP_CROP_CHARACTERISTICS_GROUP) { new StateCU_CropCharacteristics_JFrame(__dataset, editable); } else if (comp_type == StateCU_DataSet.COMP_DELAY_TABLES_GROUP) { DataSetComponent comp2 = __dataset.getComponentForComponentType(StateCU_DataSet.COMP_DELAY_TABLES_MONTHLY); if (comp2 != null) { /* * REVISIT (JTS - 2003-10-06) * old constructor * new StateMod_DelayTable_JFrame( * "Delay Tables", (Vector)comp2.getData(), * true, editable); */ } } else if (comp_type == StateCU_DataSet.COMP_CU_LOCATIONS_GROUP) { // TODO SAM 2011-06-22 Need a way to pass a window manager new StateCU_Location_JFrame(__isStateCU, __dataset, null, editable); } } // Else, data are specific objects... else if (data is StateCU_ClimateStation) { new StateCU_ClimateStation_JFrame("Climate Stations", __dataset, (StateCU_ClimateStation)data, editable); } else if (data is StateCU_CropCharacteristics) { new StateCU_CropCharacteristics_JFrame(__dataset, (StateCU_CropCharacteristics)data, editable); } else if (data is StateMod_DelayTable) { DataSetComponent comp2 = __dataset.getComponentForComponentType(StateCU_DataSet.COMP_DELAY_TABLES_MONTHLY); if (comp2 != null) { /* * REVISIT (JTS - 2003-10-06) * old constructor * new StateMod_DelayTable_JFrame( * "Delay Tables", (Vector)comp2.getData(), * (StateMod_DelayTable)data, true, editable); */ } } else if (data is StateCU_Location) { new StateCU_Location_JFrame(false, __dataset, null, (StateCU_Location)data, editable); } }