custommessages.java.svn-base
来自「开源项目openfire的完整源程序」· SVN-BASE 代码 · 共 582 行 · 第 1/2 页
SVN-BASE
582 行
if (csi.getType().equals(statusItem.getText())) { JiveTreeNode subNode = new JiveTreeNode(csi.getStatus(), false); node.add(subNode); } } rootNode.add(node); } DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); model.nodeStructureChanged(rootNode); tree.expandTree(); return; } private static class CustomStatus extends JPanel { private JLabel typeLabel = new JLabel(); private JComboBox typeBox = new JComboBox(); private JLabel statusLabel = new JLabel(); private JTextField statusField = new JTextField(); private JLabel priorityLabel = new JLabel(); private JTextField priorityField = new JTextField(); private JCheckBox persistBox = new JCheckBox(); public CustomStatus() { StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); // Add Mnemonics ResourceUtils.resLabel(typeLabel, typeBox, Res.getString("label.presence")); ResourceUtils.resLabel(statusLabel, statusField, Res.getString("label.message")); ResourceUtils.resLabel(priorityLabel, priorityField, Res.getString("label.priority")); ResourceUtils.resButton(persistBox, Res.getString("button.save.for.future.use")); setLayout(new GridBagLayout()); add(typeLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); add(statusLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); add(priorityLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); add(typeBox, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 150, 0)); add(statusField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); add(priorityField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); add(persistBox, new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); persistBox.setSelected(true); typeBox.setRenderer(new ListIconRenderer()); // Add Types Iterator statusIterator = statusBar.getStatusList().iterator(); while (statusIterator.hasNext()) { final StatusItem statusItem = (StatusItem)statusIterator.next(); ImageIcon icon = (ImageIcon)statusItem.getIcon(); ImageIcon newIcon = new ImageIcon(icon.getImage()); newIcon.setDescription(statusItem.getText()); typeBox.addItem(newIcon); } priorityField.setText("1"); statusField.setText("I'm Available"); } public String getType() { ImageIcon icon = (ImageIcon)typeBox.getSelectedItem(); return icon.getDescription(); } public String getStatus() { return statusField.getText(); } public int getPriority() { try { return Integer.parseInt(priorityField.getText()); } catch (NumberFormatException e) { return 1; } } public void showEditDialog(final CustomStatusItem item) { // Construct main panel w/ layout. final JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); // The user should only be able to close this dialog. Object[] options = {Res.getString("ok"), Res.getString("cancel")}; final JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]); mainPanel.add(optionPane, BorderLayout.CENTER); final JDialog optionsDialog = new JDialog(SparkManager.getMainWindow(), Res.getString("title.edit.custom.message"), true); optionsDialog.setContentPane(mainPanel); optionsDialog.pack(); persistBox.setVisible(false); priorityField.setText(Integer.toString(item.getPriority())); statusField.setText(item.getStatus()); String type = item.getType(); int count = typeBox.getItemCount(); for (int i = 0; i < count; i++) { ImageIcon icon = (ImageIcon)typeBox.getItemAt(i); if (icon.getDescription().equals(type)) { typeBox.setSelectedIndex(i); break; } } optionsDialog.setLocationRelativeTo(SparkManager.getMainWindow()); optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { String value = (String)optionPane.getValue(); if (Res.getString("cancel").equals(value)) { optionsDialog.setVisible(false); return; } else if (Res.getString("ok").equals(value)) { List list = load(); Iterator iter = list.iterator(); CustomStatusItem changeItem = null; while (iter.hasNext()) { CustomStatusItem customItem = (CustomStatusItem)iter.next(); if (customItem.getType().equals(item.getType()) && customItem.getStatus().equals(item.getStatus())) { changeItem = customItem; break; } } Iterator customListIterator = list.iterator(); boolean exists = false; while (customListIterator.hasNext()) { CustomStatusItem customItem = (CustomStatusItem)customListIterator.next(); String type = customItem.getType(); String status = customItem.getStatus(); if (type.equals(getType()) && status.equals(getStatus())) { exists = true; } } if (changeItem != null) { changeItem.setPriority(getPriority()); changeItem.setStatus(getStatus()); changeItem.setType(getType()); } // Otherwise save. if (!exists) { save(list); } optionsDialog.setVisible(false); } } }); optionsDialog.setVisible(true); optionsDialog.toFront(); optionsDialog.requestFocus(); } public void invoke(String selectedType) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); // Construct main panel w/ layout. final JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); // The user should only be able to close this dialog. Object[] options = {Res.getString("ok"), Res.getString("cancel")}; final JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]); mainPanel.add(optionPane, BorderLayout.CENTER); final JDialog optionsDialog = new JDialog(SparkManager.getMainWindow(), Res.getString("title.set.status.message"), true); optionsDialog.setContentPane(mainPanel); optionsDialog.pack(); if (selectedType != null) { int count = typeBox.getItemCount(); for (int i = 0; i < count; i++) { ImageIcon icon = (ImageIcon)typeBox.getItemAt(i); if (icon.getDescription().equals(selectedType)) { typeBox.setSelectedIndex(i); break; } } persistBox.setSelected(true); } optionsDialog.setLocationRelativeTo(SparkManager.getMainWindow()); optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { String value = (String)optionPane.getValue(); if (Res.getString("cancel").equals(value)) { optionsDialog.setVisible(false); } else if (Res.getString("ok").equals(value)) { if (!ModelUtil.hasLength(getStatus())) { JOptionPane.showMessageDialog(optionsDialog, Res.getString("message.invalid.status")); optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE); return; } if (!persistBox.isSelected()) { // Change presence and quit. StatusItem item = statusBar.getStatusItem(getType()); Presence oldPresence = item.getPresence(); Presence presence = StatusBar.copyPresence(oldPresence); presence.setStatus(getStatus()); presence.setPriority(getPriority()); SparkManager.getSessionManager().changePresence(presence); statusBar.setStatus(getStatus()); optionsDialog.setVisible(false); return; } List list = load(); CustomStatusItem customStatusItem = new CustomStatusItem(); customStatusItem.setPriority(getPriority()); customStatusItem.setStatus(getStatus()); customStatusItem.setType(getType()); Iterator customListIterator = list.iterator(); boolean exists = false; while (customListIterator.hasNext()) { CustomStatusItem customItem = (CustomStatusItem)customListIterator.next(); String type = customItem.getType(); String status = customItem.getStatus(); if (type.equals(customStatusItem.getType()) && status.equals(customStatusItem.getStatus())) { exists = true; } } // Otherwise save. if (!exists) { list.add(customStatusItem); // Update current status. StatusItem item = statusBar.getStatusItem(getType()); Presence oldPresence = item.getPresence(); Presence presence = StatusBar.copyPresence(oldPresence); presence.setStatus(getStatus()); presence.setPriority(getPriority()); SparkManager.getSessionManager().changePresence(presence); statusBar.setStatus(getStatus()); // Persist new item. save(list); } optionsDialog.setVisible(false); } } }); optionsDialog.setVisible(true); optionsDialog.toFront(); optionsDialog.requestFocus(); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?