/// <summary>
        /// Constructor. </summary>
        /// <param name="data"> the data to display in the worksheet.  Can be null or empty. </param>
        /// <param name="titleString"> the String to display as the GUI title. </param>
        /// <param name="editable"> whether the data in the JFrame can be edited or not.  If true
        /// the data can be edited, if false they can not. </param>
        /// <exception cref="Exception"> if there is an error building the worksheet. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public StateCU_DelayTableAssignment_Data_JFrame(java.util.List<StateCU_DelayTableAssignment_Data_TableModel> data, String titleString, boolean editable) throws Exception
        public StateCU_DelayTableAssignment_Data_JFrame(IList <StateCU_DelayTableAssignment_Data_TableModel> data, string titleString, bool editable) : base(data, titleString, editable)
        {
            JPanel panel = new JPanel();

            panel.setLayout(new GridBagLayout());
            JLabel label = new JLabel("Show totals: ");

            JGUIUtil.addComponent(panel, label, 0, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);
            __checkBox = new JCheckBox((string)null, true);
            __checkBox.addActionListener(this);
            JGUIUtil.addComponent(panel, __checkBox, 1, 0, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
            getContentPane().add("North", panel);
            pack();

            setSize(370, getHeight());
            __tableModel = (StateCU_DelayTableAssignment_Data_TableModel)_worksheet.getTableModel();
            __tableModel.setJWorksheet(_worksheet);
        }
        /// <summary>
        /// Sets up the GUI.
        /// </summary>
        private void setupGUI()
        {
            addWindowListener(this);

            __descriptionTextField = new JTextField(25);
            __origDesc             = __nodes[__nodeNum].getDescription();
            __descriptionTextField.setText(__origDesc);
            __idTextField = new JTextField(10);
            __origID      = __nodes[__nodeNum].getCommonID();
            __idTextField.setText(__origID);
            __idTextField.addKeyListener(this);
            __xTextField = new JTextField(10);
            __origX      = StringUtil.formatString(__nodes[__nodeNum].getX(), "%13.6f").Trim();
            __xTextField.setText(__origX);
            __xTextField.addKeyListener(this);
            __yTextField = new JTextField(10);
            __origY      = StringUtil.formatString(__nodes[__nodeNum].getY(), "%13.6f").Trim();
            __yTextField.setText(__origY);
            __yTextField.addKeyListener(this);
            __areaTextField = new JTextField(10);
            __origArea      = StringUtil.formatString(__nodes[__nodeNum].getArea(), "%13.6f").Trim();
            __areaTextField.setText(__origArea);
            __areaTextField.addKeyListener(this);
            __precipitationTextField = new JTextField(10);
            __origPrecipitation      = StringUtil.formatString(__nodes[__nodeNum].getPrecip(), "%13.6f").Trim();
            __precipitationTextField.setText(__origPrecipitation);
            __precipitationTextField.addKeyListener(this);

            __typeComboBox = new SimpleJComboBox(false);
            __typeComboBox.add(__NODE_DIVERSION);
            __typeComboBox.add(__NODE_DIVERSION_AND_WELL);
            __typeComboBox.add(__NODE_INSTREAM_FLOW);
            __typeComboBox.add(__NODE_OTHER);
            __typeComboBox.add(__NODE_PLAN);
            __typeComboBox.add(__NODE_RESERVOIR);
            __typeComboBox.add(__NODE_STREAMFLOW);
            __typeComboBox.add(__NODE_WELL);

            int type = __nodes[__nodeNum].getType();

            if (type == HydrologyNode.NODE_TYPE_CONFLUENCE)
            {
                __typeComboBox.select(__NODE_CONFLUENCE);
            }
            else if (type == HydrologyNode.NODE_TYPE_DIV)
            {
                __typeComboBox.select(__NODE_DIVERSION);
            }
            else if (type == HydrologyNode.NODE_TYPE_DIV_AND_WELL)
            {
                __typeComboBox.select(__NODE_DIVERSION_AND_WELL);
            }
            else if (type == HydrologyNode.NODE_TYPE_END)
            {
                __typeComboBox.removeAll();
                __typeComboBox.add(__NODE_END);
            }
            else if (type == HydrologyNode.NODE_TYPE_ISF)
            {
                __typeComboBox.select(__NODE_INSTREAM_FLOW);
            }
            else if (type == HydrologyNode.NODE_TYPE_OTHER)
            {
                __typeComboBox.select(__NODE_OTHER);
            }
            else if (type == HydrologyNode.NODE_TYPE_PLAN)
            {
                __typeComboBox.select(__NODE_PLAN);
            }
            else if (type == HydrologyNode.NODE_TYPE_RES)
            {
                __typeComboBox.select(__NODE_RESERVOIR);
            }
            else if (type == HydrologyNode.NODE_TYPE_FLOW)
            {
                __typeComboBox.select(__NODE_STREAMFLOW);
            }
            else if (type == HydrologyNode.NODE_TYPE_WELL)
            {
                __typeComboBox.select(__NODE_WELL);
            }
            else if (type == HydrologyNode.NODE_TYPE_XCONFLUENCE)
            {
                __typeComboBox.select(__NODE_XCONFLUENCE);
            }
            else
            {
                __typeComboBox.removeAll();
                __typeComboBox.add("Unknown Type: " + type);
            }

            __typeComboBox.setMaximumRowCount(__typeComboBox.getItemCount());

            __origIType = type;
            __origType  = __typeComboBox.getSelected();

            __labelPositionComboBox = new SimpleJComboBox(false);
            __labelPositionComboBox.add(__ABOVE_CENTER);
            __labelPositionComboBox.add(__UPPER_RIGHT);
            __labelPositionComboBox.add(__RIGHT);
            __labelPositionComboBox.add(__LOWER_RIGHT);
            __labelPositionComboBox.add(__BELOW_CENTER);
            __labelPositionComboBox.add(__LOWER_LEFT);
            __labelPositionComboBox.add(__LEFT);
            __labelPositionComboBox.add(__UPPER_LEFT);
            __labelPositionComboBox.add(__CENTER);
            __labelPositionComboBox.setMaximumRowCount(__labelPositionComboBox.getItemCount());

            int dir = __nodes[__nodeNum].getLabelDirection() % 10;

            if (dir == 2)
            {
                __labelPositionComboBox.select(__BELOW_CENTER);
            }
            else if (dir == 1)
            {
                __labelPositionComboBox.select(__ABOVE_CENTER);
            }
            else if (dir == 4)
            {
                __labelPositionComboBox.select(__RIGHT);
            }
            else if (dir == 3)
            {
                __labelPositionComboBox.select(__LEFT);
            }
            else if (dir == 7)
            {
                __labelPositionComboBox.select(__UPPER_RIGHT);
            }
            else if (dir == 8)
            {
                __labelPositionComboBox.select(__LOWER_RIGHT);
            }
            else if (dir == 5)
            {
                __labelPositionComboBox.select(__LOWER_LEFT);
            }
            else if (dir == 6)
            {
                __labelPositionComboBox.select(__UPPER_LEFT);
            }
            else if (dir == 9)
            {
                __labelPositionComboBox.select(__CENTER);
            }
            else
            {
                __labelPositionComboBox.removeAll();
                __labelPositionComboBox.add("Unknown Position: " + dir);
            }

            __origIDir = dir;
            __origDir  = __labelPositionComboBox.getSelected();

            __isNaturalFlowCheckBox = new JCheckBox();
            __isImportCheckBox      = new JCheckBox();

            __origDirty = __nodes[__nodeNum].isDirty();

            __reservoirDirectionLabel    = new JLabel("Reservoir Direction: ");
            __reservoirDirectionComboBox = new SimpleJComboBox(false);
            __reservoirDirectionComboBox.setToolTipText("Reservoir body is to the indicated direction " + "(downstream follows the arrow).");
            __reservoirDirectionComboBox.add(__TOP);
            __reservoirDirectionComboBox.add(__BOTTOM);
            __reservoirDirectionComboBox.add(__LEFT);
            __reservoirDirectionComboBox.add(__RIGHT);

            int resDir = __nodes[__nodeNum].getLabelDirection() / 10;

            if (resDir == 1)
            {
                __reservoirDirectionComboBox.select(__BOTTOM);
            }
            else if (resDir == 2)
            {
                __reservoirDirectionComboBox.select(__TOP);
            }
            else if (resDir == 3)
            {
                __reservoirDirectionComboBox.select(__RIGHT);
            }
            else if (resDir == 4)
            {
                __reservoirDirectionComboBox.select(__LEFT);
            }
            else if (resDir == 0)
            {
            }
            else
            {
                __reservoirDirectionComboBox.removeAll();
                __reservoirDirectionComboBox.add("Unknown direction: " + resDir);
            }

            __origResIDir = resDir;
            __origResDir  = __reservoirDirectionComboBox.getSelected();

            JPanel panel = new JPanel();

            panel.setLayout(new GridBagLayout());

            int y = 0;

            JGUIUtil.addComponent(panel, new JLabel("ID: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __idTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;
            JGUIUtil.addComponent(panel, new JLabel("Type: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __typeComboBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;
            JGUIUtil.addComponent(panel, new JLabel("Description: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __descriptionTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;
            JGUIUtil.addComponent(panel, new JLabel("X: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __xTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;
            JGUIUtil.addComponent(panel, new JLabel("Y: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __yTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;
            JGUIUtil.addComponent(panel, new JLabel("Is natural flow?: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __isNaturalFlowCheckBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;
            JGUIUtil.addComponent(panel, new JLabel("Is import?: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __isImportCheckBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;
            JGUIUtil.addComponent(panel, new JLabel("Area: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __areaTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);
            y++;
            JGUIUtil.addComponent(panel, new JLabel("Precipitation: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __precipitationTextField, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);
            if (__nodes[__nodeNum].getIsNaturalFlow())
            {
                __isNaturalFlowCheckBox.setSelected(true);
            }
            else
            {
                __isNaturalFlowCheckBox.setSelected(false);
                __areaTextField.setEnabled(false);
                __precipitationTextField.setEnabled(false);
            }
            __isNaturalFlowCheckBox.addActionListener(this);

            if (__nodes[__nodeNum].getIsImport())
            {
                __isImportCheckBox.setSelected(true);
            }
            else
            {
                __isImportCheckBox.setSelected(false);
            }
            __isImportCheckBox.addActionListener(this);

            __origNaturalFlow = __isNaturalFlowCheckBox.isSelected();
            __origImport      = __isImportCheckBox.isSelected();

            y++;
            JGUIUtil.addComponent(panel, new JLabel("Label Position: "), 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __labelPositionComboBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;
            JGUIUtil.addComponent(panel, __reservoirDirectionLabel, 0, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(panel, __reservoirDirectionComboBox, 1, y, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            y++;

            y = addUpstreamNodesToPanel(panel, y);
            addDownstreamNodeToPanel(panel, y);

            getContentPane().add(panel);

            JPanel southPanel = new JPanel();

            southPanel.setLayout(new GridBagLayout());

            __applyButton = new JButton(__BUTTON_APPLY);
            __applyButton.addActionListener(this);
            __okButton = new JButton(__BUTTON_OK);
            __okButton.addActionListener(this);
            JButton cancelButton = new JButton(__BUTTON_CANCEL);

            cancelButton.addActionListener(this);

            JGUIUtil.addComponent(southPanel, __applyButton, 0, 0, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(southPanel, __okButton, 2, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(southPanel, cancelButton, 3, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);

            getContentPane().add(southPanel, "South");

            pack();

            if (__origIType != HydrologyNode.NODE_TYPE_RES)
            {
                __reservoirDirectionLabel.setVisible(false);
                __reservoirDirectionComboBox.setVisible(false);
            }

            __typeComboBox.addActionListener(this);

            if (__parent.inStateModGUI())
            {
                __typeComboBox.setEnabled(false);
                __precipitationTextField.setEditable(false);
                __precipitationTextField.removeKeyListener(this);
                __descriptionTextField.setEditable(false);
                __descriptionTextField.removeKeyListener(this);
                __areaTextField.removeKeyListener(this);
                __areaTextField.setEditable(false);
                __idTextField.removeKeyListener(this);
                __idTextField.setEditable(false);
                __isNaturalFlowCheckBox.setEnabled(false);
                __isImportCheckBox.setEnabled(false);
            }

            JGUIUtil.center(this);
            setVisible(true);
        }
Пример #3
0
    //--------
    //-------- Constructors
    //--------

    /// <summary>
    /// Constructor a frame to contain the device data.  Provide
    /// the device and the log file name
    /// </summary>
    public TagMainFrame() : base("1-Wire Tag Viewer")
    {
        // construct the frame

        //set the look and feel to the system look and feel
        try
        {
            UIManager.LookAndFeel = UIManager.SystemLookAndFeelClassName;
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            Console.Write(e.StackTrace);
        }

        // add an event listener to end the aplication when the frame is closed
        addWindowListener(new WindowAdapterAnonymousInnerClassHelper(this, e));

        // create the main panel
        mainPanel = new JPanel(new BorderLayout(10, 10));

        // create the sub-pannels
        northPanel        = new JPanel();
        northPanel.Border = BorderFactory.createLoweredBevelBorder();

        centerPanel        = new JPanel();
        centerPanel.Layout = new BoxLayout(centerPanel, BoxLayout.Y_AXIS);

        southPanel        = new JPanel();
        southPanel.Layout = new BoxLayout(southPanel, BoxLayout.Y_AXIS);
        southPanel.Border = BorderFactory.createLoweredBevelBorder();

        westPanel        = new JPanel();
        westPanel.Border = BorderFactory.createRaisedBevelBorder();
        westPanel.Border = BorderFactory.createEmptyBorder(10, 10, 10, 10);

        eastPanel        = new JPanel();
        eastPanel.Border = BorderFactory.createEmptyBorder(10, 10, 10, 10);

        // fill the panels

        // north
        logLabel = new JLabel("Log Filename: ");
        northPanel.add(logLabel);

        logField = new JTextField("log.txt", 20);
        logField.addActionListener(this);
        northPanel.add(logField);

        // center
        listData = new DefaultListModel();
        listData.addElement("                                                                     ");
        listData.addElement("                                                                     ");
        listData.addElement("                                                                     ");
        listData.addElement("                                                                     ");
        pathList = new JList(listData);
        pathList.VisibleRowCount = 5;
        scrollPanel        = new JScrollPane(pathList);
        scrollPanel.Border = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "1-Wire Paths to Search");
        centerPanel.add(scrollPanel);

        // west
        scanCheck = new JCheckBox("Scan 1-Wire Paths for XML Tags", false);
        scanCheck.addActionListener(this);
        westPanel.add(scanCheck);

        // south
        portLabel = new JLabel("Adapter:");
        southPanel.add(portLabel);

        statusLabel = new JLabel("Status:");
        southPanel.add(statusLabel);

        // add to main
        mainPanel.add(northPanel, BorderLayout.NORTH);
        mainPanel.add(centerPanel, BorderLayout.CENTER);
        mainPanel.add(southPanel, BorderLayout.SOUTH);
        mainPanel.add(eastPanel, BorderLayout.EAST);
        mainPanel.add(westPanel, BorderLayout.WEST);

        // add to frame
        ContentPane.add(mainPanel);

        // pack the frame
        pack();

        // resize the window and put in random location
        Dimension current_sz = Size;

        Size = new Dimension(current_sz.width * 5 / 4, current_sz.height);
        Toolkit   tool = Toolkit.DefaultToolkit;
        Dimension mx   = tool.ScreenSize;
        Dimension sz   = Size;
        Random    rand = new Random();

        setLocation((mx.width - sz.width) / 2, (mx.height - sz.height) / 2);

        // clear out the listbox data
        listData.removeAllElements();

        // make visible
        Visible = true;
    }
        /// <summary>
        /// Sets up the GUI.
        /// </summary>
        private void setupGUI()
        {
            addWindowListener(__parent);

            JPanel panel = new JPanel();

            panel.setLayout(new GridBagLayout());

            int y = 0;

            __downstreamIDJTextField = new JTextField(10);
            __downstreamIDJTextField.setEditable(false);
            __downstreamIDJTextField.setText(__ds.getCommonID());
            __upstreamIDComboBox = new SimpleJComboBox(false);
            __upstreamIDComboBox.setPrototypeDisplayValue("[none] - Start a new TributaryXX");
            __nodeNameJTextField = new JTextField(10);
            __nodeNameJTextField.addKeyListener(this);

            string[] usid = __ds.getUpstreamNodesIDs();
            for (int i = 0; i < usid.Length; i++)
            {
                __upstreamIDComboBox.add(usid[i]);
            }
            __upstreamIDComboBox.add("[none] - Start a new Tributary");

            __nodeTypeComboBox = new SimpleJComboBox();

            __nodeTypeComboBox.add(__NODE_CONFLUENCE);
            __nodeTypeComboBox.add(__NODE_DIVERSION);
            __nodeTypeComboBox.add(__NODE_DIVERSION_AND_WELL);
            __nodeTypeComboBox.add(__NODE_INSTREAM_FLOW);
            __nodeTypeComboBox.add(__NODE_OTHER);
            __nodeTypeComboBox.add(__NODE_PLAN);
            __nodeTypeComboBox.add(__NODE_RESERVOIR);
            __nodeTypeComboBox.add(__NODE_STREAMFLOW);
            __nodeTypeComboBox.add(__NODE_WELL);
            __nodeTypeComboBox.add(__NODE_XCONFLUENCE);
            __nodeTypeComboBox.select(__NODE_STREAMFLOW);
            __nodeTypeComboBox.setMaximumRowCount(__nodeTypeComboBox.getItemCount());
            __nodeTypeComboBox.addActionListener(this);

            __naturalFlowJCheckBox = new JCheckBox();
            __naturalFlowJCheckBox.addActionListener(this);

            __importJCheckBox = new JCheckBox();
            __importJCheckBox.addActionListener(this);

            JPanel top = new JPanel();

            top.setLayout(new GridBagLayout());
            top.setBorder(BorderFactory.createTitledBorder("Existing nodes"));

            JPanel bottom = new JPanel();

            bottom.setLayout(new GridBagLayout());
            bottom.setBorder(BorderFactory.createTitledBorder("New Node Data"));

            JGUIUtil.addComponent(panel, top, 0, 0, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.WEST);
            JGUIUtil.addComponent(panel, bottom, 0, 1, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.WEST);

            y = 0;
            JGUIUtil.addComponent(top, new JLabel("Downstream node: "), 0, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(top, __downstreamIDJTextField, 1, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
            y++;

            JGUIUtil.addComponent(top, new JLabel("Upstream node: "), 0, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(top, __upstreamIDComboBox, 1, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
            y++;

            y = 0;
            JGUIUtil.addComponent(bottom, new JLabel("Node ID: "), 0, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(bottom, __nodeNameJTextField, 1, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
            y++;

            JGUIUtil.addComponent(bottom, new JLabel("Node type: "), 0, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(bottom, __nodeTypeComboBox, 1, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
            y++;

            JGUIUtil.addComponent(bottom, new JLabel("Is natural flow?: "), 0, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(bottom, __naturalFlowJCheckBox, 1, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
            y++;

            JGUIUtil.addComponent(bottom, new JLabel("Is import?: "), 0, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(bottom, __importJCheckBox, 1, y, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);

            JPanel southPanel = new JPanel();

            southPanel.setLayout(new GridBagLayout());

            __okJButton = new JButton(__BUTTON_OK);
            __okJButton.addActionListener(this);
            __okJButton.setEnabled(false);
            JButton cancelButton = new JButton(__BUTTON_CANCEL);

            cancelButton.addActionListener(this);

            JGUIUtil.addComponent(southPanel, __okJButton, 0, 0, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
            JGUIUtil.addComponent(southPanel, cancelButton, 1, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST);

            getContentPane().add(panel);
            getContentPane().add(southPanel, "South");

            pack();
            JGUIUtil.center(this);
            setVisible(true);
        }
Пример #5
0
    //--------
    //-------- Constructors
    //--------

    /// <summary>
    /// Constructor a frame to contain the device data.  Provide
    /// the device and the log file name
    /// </summary>
    public DeviceFrame(TaggedDevice dev, string logFile) : base(dev.DeviceContainer.AddressAsString)
    {
        // construct the frame

        // init
        pollDelay       = 0;
        readButtonClick = false;
        num_format      = NumberFormat.Instance;
        num_format.MaximumFractionDigits = 2;
        num_format.MinimumFractionDigits = 0;
        num_format.MinimumIntegerDigits  = 2;
        num_format.GroupingUsed          = false;
        lastReading = "none";

        // get ref to the tagged device and log file
        this.dev     = dev;
        this.logFile = logFile;

        // set the look and feel to the system look and feel
        try
        {
            UIManager.LookAndFeel = UIManager.SystemLookAndFeelClassName;
        }
        catch (Exception e)
        {
            Debug.WriteLine(e.ToString());
            Debug.Write(e.StackTrace);
        }

        // add an event listener to end the aplication when the frame is closed
        addWindowListener(new WindowAdapterAnonymousInnerClassHelper(this, e));

        // create the main panel
        mainPanel = new JPanel(new GridLayout(3, 1));

        // create the sub-panels
        topPanel        = new JPanel();
        topPanel.Layout = new BoxLayout(topPanel, BoxLayout.Y_AXIS);
        topPanel.Border = BorderFactory.createEmptyBorder(10, 10, 10, 10);

        centerPanel            = new JPanel();
        centerPanel.Layout     = new BoxLayout(centerPanel, BoxLayout.Y_AXIS);
        centerPanel.Border     = BorderFactory.createEmptyBorder(10, 10, 10, 10);
        centerPanel.Background = Color.white;

        bottomPanel        = new JPanel();
        bottomPanel.Layout = new BoxLayout(bottomPanel, BoxLayout.Y_AXIS);
        bottomPanel.Border = BorderFactory.createEmptyBorder(10, 10, 10, 10);

        // fill the panels
        // top
        clusterLabel = new JLabel("Cluster: " + dev.ClusterName);
        topPanel.add(clusterLabel);

        mainLabel = new JLabel(dev.Label);
        mainLabel.HorizontalAlignment = JLabel.CENTER;
        mainLabel.Font = new Font("SansSerif", Font.PLAIN, 20);
        topPanel.add(mainLabel);

        logCheck = new JCheckBox("Logging Enable", false);
        logCheck.addActionListener(this);
        topPanel.add(logCheck);

        // center
        timeLabel = new JLabel("Last Reading: none");
        timeLabel.HorizontalAlignment = JLabel.CENTER;
        centerPanel.add(timeLabel);

        // bottom
        readButton            = new JButton("Read Once");
        readButton.AlignmentX = Component.LEFT_ALIGNMENT;
        readButton.addActionListener(this);
        bottomPanel.add(readButton);

        string[] selectionStrings = new string[] { "No Polling", "1 second", "30 seconds", "1 minute", "10 minutes", "1 hour" };
        pollCombo            = new JComboBox(selectionStrings);
        pollCombo.Editable   = false;
        pollCombo.AlignmentX = Component.LEFT_ALIGNMENT;
        pollCombo.addActionListener(this);
        bottomPanel.add(pollCombo);

        pathLabel            = new JLabel("Path: " + dev.OWPath.ToString());
        pathLabel.AlignmentX = Component.LEFT_ALIGNMENT;
        bottomPanel.add(pathLabel);

        // add to main
        mainPanel.add(topPanel);
        mainPanel.add(centerPanel);
        mainPanel.add(bottomPanel);

        // add to frame
        ContentPane.add(mainPanel);

        // pack the frame
        pack();

        // resize the window and put in random location
        Dimension current_sz = Size;

        Size = new Dimension(current_sz.width * 3 / 2, current_sz.height);
        Toolkit   tool = Toolkit.DefaultToolkit;
        Dimension mx   = tool.ScreenSize;
        Dimension sz   = Size;
        Random    rand = new Random();

        setLocation(rand.Next((mx.width - sz.width) / 2), rand.Next((mx.height - sz.height) / 2));

        // make visible
        Visible = true;
    }
        /// <summary>
        /// Sets up the GUI.
        /// </summary>
        private void setupGUI()
        {
            string routine = "setupGUI";

            addWindowListener(this);

            __addRowButton         = new SimpleJButton(__BUTTON_ADD_ROW, this);
            __deleteRowButton      = new SimpleJButton(__BUTTON_DELETE_ROW, this);
            __saveTemplateButton   = new SimpleJButton(__BUTTON_SAVE_FILE, this);
            __clearWorksheetButton = new SimpleJButton(__BUTTON_CLEAR_LIST, this);
            __loadTemplateButton   = new SimpleJButton(__BUTTON_LOAD_FILE, this);
            __helpButton           = new SimpleJButton(__BUTTON_HELP, this);
            __helpButton.setEnabled(false);
            __closeButton = new SimpleJButton(__BUTTON_CLOSE, this);

            __useAllJCheckBox = new JCheckBox(__CHECKBOX_USE_ALL, false);
            __useAllJCheckBox.addActionListener(this);

            // Make a main panel to be the resizable body of the frame...

            JPanel        main_JPanel = new JPanel();
            GridBagLayout gb          = new GridBagLayout();

            main_JPanel.setLayout(gb);

            GridLayout gl        = new GridLayout(2, 2, 2, 2);
            JPanel     top_panel = new JPanel();

            top_panel.setLayout(gl);

            JPanel radio_panel = new JPanel();

            radio_panel.setLayout(gb);

            GridLayout gl2           = new GridLayout(1, 0, 2, 0);
            JPanel     bottom_JPanel = new JPanel();

            bottom_JPanel.setLayout(gl2);

            FlowLayout fl = new FlowLayout(FlowLayout.CENTER);
            JPanel     final_button_JPanel = new JPanel();

            final_button_JPanel.setLayout(fl);

            JPanel grid_JPanel = new JPanel();

            grid_JPanel.setLayout(gb);


            // add add a row, delete selected rows, clear spreadsheet,
            // select template, save template buttons
            top_panel.add(__addRowButton);
            top_panel.add(__deleteRowButton);
            top_panel.add(__clearWorksheetButton);
            top_panel.add(__loadTemplateButton);
            int y = 0;

            JGUIUtil.addComponent(main_JPanel, top_panel, 0, y, 10, 3, 0, 0, 10, 10, 10, 10, GridBagConstraints.NONE, GridBagConstraints.NORTH);

            y += 3;
            JGUIUtil.addComponent(main_JPanel, __useAllJCheckBox, 0, ++y, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST);

            PropList p = new PropList("StateMod_OutputControl_JFrame.JWorksheet");

            p.add("JWorksheet.ShowRowHeader=true");
            p.add("JWorksheet.AllowCopy=true");
            p.add("JWorksheet.ShowPopupMenu=true");

            int[]            widths = null;
            JScrollWorksheet jsw    = null;

            try
            {
                __tableModel = new StateMod_OutputControl_TableModel(this, new List <object>(), (System.Collections.IList)__riverNetworkComp.getData());

                StateMod_OutputControl_CellRenderer cro = new StateMod_OutputControl_CellRenderer(__tableModel);

                jsw         = new JScrollWorksheet(cro, __tableModel, p);
                __worksheet = jsw.getJWorksheet();

                System.Collections.IList v = StateMod_Util.arrayToList(StateMod_GraphNode.node_types);
                v.Add("Other");
                __worksheet.setColumnJComboBoxValues(0, v);

                __worksheet.setCellSpecificJComboBoxColumn(1, false);

                System.Collections.IList offOn = new List <object>();
                offOn.Add("Off");
                offOn.Add("On");
                __worksheet.setColumnJComboBoxValues(2, offOn);

                __tableModel.setWorksheet(__worksheet);

                widths = cro.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);

            JGUIUtil.addComponent(grid_JPanel, jsw, 0, 0, 1, 1, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.CENTER);

            JGUIUtil.addComponent(main_JPanel, grid_JPanel, 0, ++y, 10, 12, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.CENTER);

            y += 11;     // To account for grid height

            // Add bottom buttons - these are alphabetical so be
            //	careful if you add more ...

            final_button_JPanel.add(__closeButton);
            // REVISIT SAM 2006-03-04
            // Help is not currently enabled
            //final_button_JPanel.add(__helpButton);
            final_button_JPanel.add(__saveTemplateButton);

            // Add the final buttons on the bottom to the bottom panel...
            bottom_JPanel.add(final_button_JPanel);
            // Add the button panel to the frame...
            JGUIUtil.addComponent(main_JPanel, bottom_JPanel, 0, ++y, 10, 1, 0, 0, GridBagConstraints.VERTICAL, GridBagConstraints.SOUTH);

            // Add the main panel as the resizable content...

            getContentPane().add("Center", main_JPanel);

            // Add JTextFields for messages...
            JPanel message_JPanel = new JPanel();

            message_JPanel.setLayout(gb);
            __messageJTextField = new JTextField();
            __messageJTextField.setEditable(false);
            __statusJTextField = new JTextField("             ");
            __statusJTextField.setEditable(false);
            JGUIUtil.addComponent(message_JPanel, __messageJTextField, 0, 0, 9, 1, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
            JGUIUtil.addComponent(message_JPanel, __statusJTextField, 9, 0, 1, 1, 0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.SOUTH);
            getContentPane().add("South", message_JPanel);

            pack();
            setSize(670, 500);
            JGUIUtil.center(this);
            setVisible(true);

            if (widths != null)
            {
                __worksheet.setColumnWidths(widths);
            }
        }