📄 editor.java
字号:
}; popupMenu.add(action); popupMenu.addSeparator(); action = new AbstractAction("Edit") { public void actionPerformed(ActionEvent e) { if (!showUserColumns.isSelected() &&!showAdminColumns.isSelected()) { JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(), "Select \"Show user data\" and/or \"Show admin data\" to edit an account."); } else { TaskEdit task = new TaskEdit(Editor.this); task.start(); } } }; popupMenu.add(action); action = new AbstractAction("Delete") { public void actionPerformed(ActionEvent e) { TaskDelete task = new TaskDelete(Editor.this); task.start(); } }; popupMenu.add(action); action = new AbstractAction("New") { public void actionPerformed(ActionEvent e) { if (userPanel == null) { return; } if (!showUserColumns.isSelected() &&!showAdminColumns.isSelected()) { JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(), "Select \"Show user data\" and/or \"Show admin data\" to create a new account."); return; } userPanel.setMode(UserPanel.ADD_NEW_MODE); // Load the "default" values into the new user screen Vector dummyUser = data.getDummyUser(); userPanel.setUserData(dummyUser); showUserEditorDialog(); if (userPanel.getLastButtonClicked() == UserPanel.BUTTON_OK) { Vector newData = userPanel.getUserData(); String newUsername = (String) newData.elementAt(data.USER_NAME); if (newUsername == null) //they didn't change the name so it must still be the default { newUsername = (String)dummyUser.elementAt(UserTableModel.USER_NAME); } // Check if another user with the same name exists already if (data.userExists(newUsername)) { JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(), "The user named " + newUsername + " already exists. New user not created."); return; } // Now still need to find out if there is an alias with that name: if (data.aliasExists(newUsername)) { JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(), "An alias named " + newUsername + " already exists. New user not created."); return; } data.addUser(dummyUser); int userRow = data.getRowCount() - 1; for (int i = 0; i <= UserTableModel.MAX_COLUMN_ID; i++) { String dataElement = (String) newData.elementAt(i); if (dataElement != null) { try { data.setValueAt(dataElement, userRow, i); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(), "Could not set value " + i + " for user " + data.getValueAt(userRow, UserTableModel.USER_NAME) + " because:\n\n " + ex); } } } data.fireTableDataChanged(); try { data.writeBackUserAt(userRow, true, true); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(), "Could not save data for user " + data.getValueAt(userRow, UserTableModel.USER_NAME) + " because:\n\n " + ex); } // After the new user has been added, sort the main table data.sortByUserName(); 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 = Editor.this.getWidth(); int modx = e.getX() % width; int height = Editor.this.getHeight(); int mody = e.getY() % height; popupMenu.show(Editor.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 (userPanel != null) { userPanel.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 (userPanel != null) { userPanel.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(); } }); */ showAliases = new JCheckBox("Show aliases"); showAliases.setSelected(false); showAliases.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (showAliases.isSelected()) { data.showAliases(true); } else { data.showAliases(false); } } }); showAllUsers = new JCheckBox("Load all users"); showAllUsers.setSelected(false); showAllUsers.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (showAllUsers.isSelected()) { loadAllUsers(); } } }); // layout the buttons in the panel JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(showAliases); panel.add(showAdminColumns); panel.add(showUserColumns); panel.add(showAllUsers); //panel.add(loadAll); //panel.add(find); panel.add(Box.createHorizontalGlue()); add(panel, BorderLayout.NORTH); 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); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -