📄 statusdialog.java
字号:
} /** * Description of the Method */ private void okHandler() { String statusText = itemText.getText(); if(!statusProps.containsValue(statusText)) { if(statusProps.addMessage(statusText)) { statusProps.saveToFile(); } } Settings.getInstance().setProperty("priority", priorityBox.getText()); BuddyList.getInstance().setStatus(mode, statusText, false); dispose(); } /** * Description of the Method */ private void cancelHandler() { BuddyList.getInstance().getStatusMenu().setModeChecked( BuddyList.getInstance().getCurrentPresenceMode()); dispose(); } /** * Description of the Method */ private void deleteHandler() { if(model.getSize() < 2) { JOptionPane.showMessageDialog(null, "This is the last entry. Make another to remove it."); return; } int i = JOptionPane.showConfirmDialog(null, "Do you really want to remove this presence message?", "", 0, 1); if(i == 0) { i = statusList.getSelectedIndex(); String temp = (String) statusList.getSelectedValue(); statusProps.remove(mode + "." + temp); if(i > 0) { statusList.setSelectedIndex(i - 1); } else { statusList.setSelectedIndex(i + 1); } model.removeItem(temp); statusProps.saveToFile(); statusHandler(); } } /** * Description of the Method */ private void changeNameHandler() { String key; while(true) { key = JOptionPane.showInputDialog("Please enter this status name:"); if(key.equals("") == true) { JOptionPane.showMessageDialog(null, "Presence name must be not blank! Please, enter name."); } else if((statusProps.containsKey(modeString + "." + key) == false)) { break; } else { JOptionPane.showMessageDialog(null, "This name is already taken! Pease, choose other name."); } } if(key.equals(null) == false) { String selected = (String) statusList.getSelectedValue(); String message = (String) statusProps.get(mode + "." + selected); statusProps.remove(mode + "." + selected); statusProps.put(mode + "." + key, message); model.removeItem(selected); model.addItem(key); statusList.setSelectedValue(key, true); statusProps.saveToFile(); } } /** * Description of the Method */ private void statusHandler() { itemText.setText((String) statusProps.get(modeString + "." + (String) statusList.getSelectedValue())); } /** * The model that represents the list of buddies in the room * * @author Adam Olsen * @created April 12, 2005 * @version 1.0 */ class StatusListModel extends AbstractListModel { private Vector statuses = new Vector(); /** * @return the number of elements in the list */ public int getSize() { return statuses.size(); } /** * @param row the element you want to get * @return the Object at <tt>row</tt> */ public Object getElementAt(int row) { return statuses.get(row); } /** * @param status The feature to be added to the Item attribute */ public void addItem(String status) { statuses.add(status); fireChanged(); } /** * Removes a buddy from the list * * @param status Description of the Parameter */ public void removeItem(String status) { statuses.remove(status); fireChanged(); } StatusListModel thisPointer = this; /** * Fires a change of the list */ private synchronized void fireChanged() { SwingUtilities.invokeLater( new Runnable() { public void run() { fireContentsChanged(thisPointer, 0, statuses.size()); statusList.validate(); } }); } } /** * Description of the Class * * @author synic * @created April 12, 2005 */ private class StatusMessageProperties extends Properties { private File propDir; private File propFile; private int tempIndex = 0; /** *Constructor for the StatusMessageProperties object */ public StatusMessageProperties() { this(JBother.profileDir, "statusmessages.properties"); } /** *Constructor for the StatusMessageProperties object * * @param propDir Description of the Parameter * @param propFile Description of the Parameter */ private StatusMessageProperties(String propDir, String propFile) { this.propDir = new File(propDir); this.propFile = new File(propDir, propFile); loadFromFile(); } /** * Description of the Method */ public void loadFromFile() { if(!propDir.isDirectory()) { if(!propDir.isDirectory() && !propDir.mkdirs()) { com.valhalla.Logger.debug("Could not create directory for StatusMessageProperties file! (" + propDir.getName() + ")"); } } if(propFile.isFile()) { try { InputStream is = new FileInputStream(propFile); load(is); is.close(); } catch(Exception e) { com.valhalla.Logger.debug("Could not load away message properties file"); com.valhalla.Logger.debug(e.getMessage()); } } } /** * Adds a feature to the Message attribute of the StatusMessageProperties object * * @param message The feature to be added to the Message attribute * @return Description of the Return Value */ public boolean addMessage(String message) { String key; while(true) { key = JOptionPane.showInputDialog("Please enter this status name:"); if(key.equals("") == true) { JOptionPane.showMessageDialog(null, "Presence name must be not blank! Please, enter name."); } else if((statusProps.containsKey(modeString + "." + key) == false)) { break; } else { JOptionPane.showMessageDialog(null, "This name is already taken! Pease, choose other name."); } } if(key.equals(null) == false) { model.addItem(key); itemText.setText(message); statusProps.put(mode + "." + key, message); return true; } return false; } /** * Description of the Method */ public void saveToFile() { StatusMessageProperties propCopy = (StatusMessageProperties) clone(); clear(); int i = 0; for(Enumeration e = propCopy.propertyNames(); e.hasMoreElements(); i++) { String propName = (String) e.nextElement(); setProperty(propName, propCopy.getProperty(propName)); } if(propDir.isDirectory()) { try { OutputStream os = new FileOutputStream(propFile); store(os, "StatusMessages"); os.close(); } catch(Exception e) { com.valhalla.Logger.debug("Could not save away message properties file"); com.valhalla.Logger.debug(e.getMessage()); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -