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

📄 adddellist.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public abstract void deleteItem();    
    
    /**
     * On clicking of a button the respective abstract methods are then called. 
     * <p>
     * The ListBox can also be made to clear its selection, by right clicking on
     * the listbox and clicking on the clear selection pop up menu.
     */
    public void actionPerformed(ActionEvent av)
    {
        if (av.getSource() == addButton)
        {
            addItem();
        }
        if (av.getSource() == replaceButton)
        {
            replaceItem();
        }
        if (av.getSource() == deleteButton)
        {
            deleteItem();
        }
        if (av.getActionCommand().equals("clear_selection"))
        {
            listBox.clearSelection();
        }
    }
    
    /**
     *  Method that given the Y-Coordinate, will return the corresponding 
     *  value in the JList (listBox)
     *
     *  @param  y   The Y-Coordinate.
     *
     *  @return     The Current Row that corresponds to the Y mouse Value.
     */
    public int convertYToRow(int y)
    {
        for (int row = 0; row < getListData().length; ++row)
        {
            int rowHeight = listBox.getFixedCellHeight();

            if (y < rowHeight)
            return row;
            y -= rowHeight;
        }
        return -1;
    }

    
    public void mouseClicked(MouseEvent e)
    {
    }
    
    public void mouseEntered(MouseEvent e)
    {
    }
    
    public void mouseExited(MouseEvent e)
    {
    }
    
    public void mousePressed(MouseEvent e)
    {
        if (e.getSource() == listBox)
        {
            setSelectedIndex(convertYToRow(e.getY()));
            if (convertYToRow(e.getY()) == -1)
            {
                listBox.clearSelection();
            }
            
            itemSelected();
        }        
        if (getSelectedIndex() != -1) checkForTriggerEvent(e);
    }
    
    public void mouseReleased(MouseEvent e)
    {
        if (e.getSource() == listBox)
        {
            setSelectedIndex(convertYToRow(e.getY()));
            if (convertYToRow(e.getY()) == -1)
            {
                listBox.clearSelection();
            }
            
            itemSelected();
        }        
        if (getSelectedIndex() != -1) checkForTriggerEvent(e);
    }
    
    private void checkForTriggerEvent(MouseEvent e)
    {
        if (e.isPopupTrigger())
        {
            popupMenu.show(e.getComponent(), e.getX(), e.getY());
        }
    }
    
    /**
     *  A method to remove the Add Button from the panel given by
     *  the getContentPanel() method. This will return the panel that
     *  can then be reused or replaced where needed.
     *
     *  @return     A panel containing the Add Button and its functionality
     */
    public JPanel removeAddButton()
    {
       viewDisplay.remove(addDisplay);
       return addDisplay;
    }
    
    /**
     *  A method to remove the Replace Button from the panel given by
     *  the getContentPanel() method. This will return the panel that
     *  can then be reused or replaced where needed.
     *
     *  @return     A panel containing the Replace Button and its functionality
     */
    public JPanel removeReplaceButton()
    {
       viewDisplay.remove(replaceDisplay);
       return replaceDisplay;
    }
        
    /**
     *  A method to remove the Delete Button from the panel given by
     *  the getContentPanel() method. This will return the panel that
     *  can then be reused or replaced where needed.
     *
     *  @return     A panel containing the Delete Button and its functionality
     */    
    public JPanel removeDeleteButton()
    {
       viewDisplay.remove(deleteDisplay);
       return deleteDisplay;
    }        

    /**
     *  A method to remove the listBox JList from the panel given by
     *  the getContentPanel() method. This will return the panel that
     *  can then be reused or replaced where needed.
     *
     *  @return     A panel containing the Delete Button and its functionality
     */    
    public JPanel removeListBox()
    {
       viewDisplay.remove(listBoxDisplay);
       return listBoxDisplay;
    }            
    
   /**
    *  Sets the text the component will show.  
    *
    *  @param internalName         The internal name used in the program.     
    *  @param internationalName    The international name to set the text to.
    */
    public void setCaption(String internalName, String internationalName)
    {        
        if (internalName.equals("ADD_BUTTON"))
        {
            addButton.setText(internationalName);
        }
        else if (internalName.equals("DELETE_BUTTON"))
        {
            deleteButton.setText(internationalName);
        }
        else if (internalName.equals("REPLACE_BUTTON"))
        {
            replaceButton.setText(internationalName);
        }
        else if (internalName.equals("CLEAR_POP_MENU"))
        {
            items[0].setText(internationalName);
        }
    }
    
    /**
     *  A method that sets the data to be displayed in the list component
     *
     *  @param arguments   An array of strings to set the List Data.
     */
    public void setListData(String[] arguments)
    {
        if (arguments==null) arguments=new String[0];
        
        //Sorting a sorted array should not hurt, this is here just for sorting non nodeItemLists components
        //Arrays.sort(arguments);
        listData = arguments;
        listBox.setListData(arguments);
    }
    
    /**
     *  A method that gets the data of the list component.
     *
     *  @return   An array of strings of the List Data items.
     */
    public String[] getListData()
    {
        return listData;
    }
    
    /**
     *  Returns the Selected index of the List Component
     *
     *  @return     An integer with the current index of the selected Value in the List.
     */
    public int getSelectedIndex()
    {
        return listBox.getSelectedIndex();
    }
    
    /**
     *  Sets the Selected index of the List Component
     *
     *  @param idx   An integer with the wanted index of the selected Value in the List.
     */
    public void setSelectedIndex(int idx)
    {
       listBox.setSelectedIndex(idx);
    }    
    
    /**
     *  Method that adds a component to a JPanel when the Layout is of GridBagLayout Type.
     *
     *  @param component        The component to add the the JPanel.
     *  @param pane             The JPanel to add the component on.
     *  @param row              The Row to start placing the component in.
     *  @param column           The Column to start placing the component in.
     *  @param width            The amount of rows the component can be placed on.
     *  @param height           The amount of columns the component can be placed on.
     *  @param anchor           The anchor GridBagLayout constraints.
     *  @param weightx          The proportion to grow in the x direction.
     *  @param weighty          The proportion to grow in the y direction.
     *  @param fill             The Directions GridBagLayout Constant for which to fill.
     */
    public void addComponent(Component component, JPanel pane, int row, int column, 
                                int width, int height, int anchor, double weightx, 
                                double weighty, int fill)
    {
        constraints.gridx = column;
        constraints.gridy = row;
        
        constraints.gridwidth = width;
        constraints.gridheight = height;
        
        constraints.anchor = anchor;
        constraints.weightx = weightx;
        constraints.weighty = weighty;
        constraints.fill = fill;
        
        pane.add(component, constraints);
    }
}

⌨️ 快捷键说明

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