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

📄 accrediteditor.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	                  + " already exists. New group not created.");
	
	          return;
	        }
	        
	        /*
	        // Now still need to find out if there is an alias with that name:
	        if (data.aliasExists(newGroupname))
	        {
	          JOptionPane.showMessageDialog(AccreditEditor.this.getTopLevelAncestor(),
	                  "An alias named " + newGroupname
	                  + " already exists. New group not created.");
	
	          return;
	        }
	        */
	        data.addGroup(dummyGroup);
	        
	        int groupRow = data.getRowCount() - 1;

	        for (int i = 0; i <= AccreditGroupModel.MAX_COLUMN_ID; i++)
	        {
	          String dataElement = (String) newData.elementAt(i);
	
	          if (dataElement != null)
	          {
	            try
	            {
	              data.setValueAt(dataElement, groupRow, i);
	            }
	            catch (Exception ex)
	            {
	              ex.printStackTrace();
	              JOptionPane.showMessageDialog(AccreditEditor.this.getTopLevelAncestor(),
	                      "Could not set value " + i + " for user "
	                      + data.getValueAt(groupRow, AccreditGroupModel.GROUP_NAME)
	                      + " because:\n\n " + ex);
	            }
	          }
	        }
        
        	data.fireTableDataChanged();
        
	        try
	        {
	          data.writeBackGroupAt(groupRow, true, true);
	        }
	        catch (Exception ex)
	        {
	          ex.printStackTrace();
	          JOptionPane.showMessageDialog(AccreditEditor.this.getTopLevelAncestor(),
	                  "Could not save data for user "
	                  + data.getValueAt(groupRow, AccreditGroupModel.GROUP_NAME)
	                  + " because:\n\n " + ex);
	        }
        
	        // After the new user has been added, sort the main table
	        data.sortByGroupName();
	        
	        data.fireTableDataChanged();
	        
      }
      }
    };
   

    popupMenu.add(action);

    RowSelectionListener listener = new RowSelectionListener();

    table.addMouseListener(listener);
    scroller.addMouseListener(listener);
  }


  private class RowSelectionListener extends MouseAdapter
  {
    public void mouseReleased(MouseEvent e)
    {
      if ((e.getModifiers() & InputEvent.BUTTON3_MASK)
          == InputEvent.BUTTON3_MASK)
      {

        // This is still not right. Needs more work. The problem is that the
        // e.getx method does not return the correct value once the table has
        // been scrolled.
        int width = AccreditEditor.this.getWidth();
        int modx = e.getX() % width;

        int height = AccreditEditor.this.getHeight();
        int mody = e.getY() % height;

        popupMenu.show(AccreditEditor.this, modx, mody);
      }
    }

  }

  private class ColumnModelListener implements ActionListener
  {
    private Vector removedUserColumns = new Vector();
    private Vector removedAdminColumns = new Vector();

    public void actionPerformed(ActionEvent e)
    {
      TableColumnModel columnModel = table.getColumnModel();
      JCheckBox source = (JCheckBox) e.getSource();

      if (source == showAdminColumns)
      {

        // The panel where users are edited may have not been created if one of
        // the system configuration files was missing from the pserver
        if (accreditadd != null)
        {
        	accreditadd.setShowAdmin(source.isSelected());
        }

        if (source.isSelected())        // add columns
        {
          int max = removedAdminColumns.size();

          for (int i = 0; i < max; i++)
          {
            ColumnInfo column = (ColumnInfo) removedAdminColumns.elementAt(0);

            removedAdminColumns.remove(0);
            columnModel.addColumn(column);

            if (columnModel.getColumnCount() - 1 > column.getPosition())
            {
              columnModel.moveColumn(columnModel.getColumnCount() - 1,
                      column.getPosition());
            }
          }
        }
        else                            // remove columns
        {
          for (int i = 0; i < data.getColumns().length; i++)
          {
            ColumnInfo column = data.getColumns()[i];

            if (data.getAdminColumnIndices().contains(new Integer(column.getPosition())))
            {
              Enumeration columnsInModel = columnModel.getColumns();

              while (columnsInModel.hasMoreElements())
              {
                Object columnInModel = columnsInModel.nextElement();

                if (columnInModel.equals(column))
                {
                  columnModel.removeColumn(column);
                  removedAdminColumns.add(column);
                }                       // end if model contains column
              }                         // end while
            }
          }
        }
      }                                 // end source = admin
      else if (source == showUserColumns)
      {
        if (accreditadd != null)
        {
        	accreditadd.setShowUser(source.isSelected());
        }

        if (source.isSelected())        // add columns
        {
          int max = removedUserColumns.size();

          for (int i = 0; i < max; i++)
          {
            ColumnInfo column = (ColumnInfo) removedUserColumns.elementAt(0);

            removedUserColumns.remove(0);
            columnModel.addColumn(column);

            if (columnModel.getColumnCount() - 1 > column.getPosition())
            {
              columnModel.moveColumn(columnModel.getColumnCount() - 1,
                      column.getPosition());
            }
          }
        }                               // end if add columns
        else                            // remove columns
        {
          for (int i = 0; i < data.getColumns().length; i++)
          {
            ColumnInfo column = data.getColumns()[i];

            // if this is a user column
            if (data.getUserColumnIndices().contains(new Integer(column.getPosition())))
            {
              Enumeration columnsInModel = columnModel.getColumns();

              while (columnsInModel.hasMoreElements())
              {
                Object columnInModel = columnsInModel.nextElement();

                if (columnInModel.equals(column))
                {
                  columnModel.removeColumn(column);
                  removedUserColumns.add(column);
                }                       // end if model contains column
              }                         // end while
            }                           // end if this is a user column
          }                             // end for all columns
        }                               // end remove user columns
      }
    }                                   // end method actionPerformed

  }

  public void return_login()
  {
	//adminDialog = new 
	  AdministrativeLoginPanel.adminDialog.setVisible(false);
  }
  private void createButtons()
  {
  	
	  showAdminColumns = new JCheckBox("Show admin data");

	    showAdminColumns.setSelected(true);
	    showAdminColumns.addActionListener(columnListener);

	    showUserColumns = new JCheckBox("Show user data");

	    showUserColumns.setSelected(false);
	    showUserColumns.addActionListener(columnListener);
    
	    /*
    JButton loadAll = new JButton("Load all users");

    loadAll.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        loadAllUsers();
      }

    });
   */
    

    // layout the buttons in the panel
    JPanel panel = new JPanel();

    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));    
   
    //panel.add(loadAll);
    //panel.add(find);
    panel.add(Box.createHorizontalGlue());
    add(panel, BorderLayout.NORTH);
    
    JPanel panelb = new JPanel();
    panelb.setLayout(new BoxLayout(panelb, BoxLayout.X_AXIS));
    
    JButton find = new JButton("Find");

    find.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        findDialog.setVisible(true);
      }

    });
    find.setToolTipText("Scroll to user with a given name");
    
    JButton back = new JButton("Accredit");
    back.addActionListener(new ActionListener()
    {
           public void actionPerformed(ActionEvent e)
           {
           	return_login();
             //adminDialog.setVisible(false);
           	
           }
    });
    
    JButton help = new JButton("help");
    help.addActionListener(new ActionListener()
    {
         public void actionPerformed(ActionEvent e)
         {
         	JOptionPane.showMessageDialog(getTopLevelAncestor(), 
	  	                "Extend Multimedia Server\n\n" 
	  	                + "帐号管理可以用于用户帐号添加、编辑、删除\n" +
	  	                "并且可以查询用户", "Login Help", JOptionPane.INFORMATION_MESSAGE);
             //adminDialog.setVisible(false);
         }
    });
    panelb.add(showAdminColumns);
    panelb.add(showUserColumns);
    panelb.add(find);
    panelb.add(back);
    panelb.add(help);
    panelb.add(Box.createHorizontalGlue());
    add(panelb, BorderLayout.SOUTH);
  }

  public void loadGroupNames()
  {
    AccreditTaskLoadGroupNames task = new AccreditTaskLoadGroupNames(this);

    task.start();
  }


  public void loadAllUsers()
  {
    //TaskLoadAllUsers task = new TaskLoadAllUsers(this);

    //task.start();
  }     // end method loadAllUsers


  /**
   * The renderer used to draw any cells which may have an on/off or true/false
   * value as a check box instead of a string. <p>
   * The checkbox cannot simply be used as the default renderer for the
   * concerned columns because they may not always have a value displayed in
   * them. When the data is not loaded yet from the provisioning server, the
   * value of these columns will be an empty string which will cause an
   * exception if a check box rendrer is used. So this class returns a check
   * box for cases where the value is loaded and an empty text label for cases
   * where it is not.
   */
  private class UserRenderer extends DefaultTableCellRenderer
  {
    private JCheckBox check = new JCheckBox();

    UserRenderer()
    {
      super();

      check.setHorizontalAlignment(check.CENTER);
    }

    public Component getTableCellRendererComponent(JTable table,
            Object value, boolean isSelected, boolean hasFocus, int row,
            int column)
    {
      TableModel model = table.getModel();
      Component renderer = this;

      // display the true/false and on/off values as check boxes
      int modelColumn = table.convertColumnIndexToModel(column);

      if (model.getValueAt(row, modelColumn).equals("true")
          || model.getValueAt(row, modelColumn).equals("ON"))
      {
        check.setSelected(true);

        renderer = check;
      }
      else if (model.getValueAt(row, modelColumn).equals("false")
               || model.getValueAt(row, modelColumn).equals("OFF"))

      {
        check.setSelected(false);

        renderer = check;
      }
      else if (model.getValueAt(row, AccreditGroupModel.IS_ALIAS).equals("true"))
      {

        // make the aliases italic
        value = "<html><font color=gray size=-1><i>" + value.toString()
                + "</i></font>";
      }

      setValue(value);

      setFont(table.getFont());

      if (isSelected)
      {
        renderer.setBackground(table.getSelectionBackground());
        renderer.setForeground(table.getSelectionForeground());
      }
      else
      {
        renderer.setBackground(table.getBackground());
        renderer.setForeground(table.getForeground());
      }

      return renderer;
    }

  }


  public void showGroupEditorDialog()
  {
    userEditorDialog.pack();

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

    if (userEditorDialog.getHeight() > d.getHeight() - 80)
    {
      userEditorDialog.setSize(new Dimension(userEditorDialog.getWidth()
              + 20, (int) d.getHeight() - 80));
    }
    userEditorDialog.setVisible(true);
  }

  public JTable getTable()
  {
    return table;
  }
  
  
  public AccreditGroupModel getData()
  {
    return data;
  }

  public AccreditAdd getAccreditAdd()
  {
    return accreditadd;
  }

  public JDialog getUserEditorDialog()
  {
    return userEditorDialog;
  }

  public boolean isShowAdminColumnsSelected()
  {
    return showAdminColumns.isSelected();
  }

  public boolean isShowUserColumnsSelected()
  {
    return showUserColumns.isSelected();
  }

}       // end class JPanel

⌨️ 快捷键说明

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