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

📄 visibilitysettingspanel.java

📁 一个类似QQ的在线通讯聊天软件原码,适合初学者参考学习。
💻 JAVA
字号:
package openicq.gui;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import javax.swing.border.Border;import javax.swing.table.DefaultTableModel;import javax.swing.table.TableColumn;import openicq.Start;import openicq.data.Resource;import openicq.net.VisibilityBroadcast;import org.javalib.gui.model.SettingsDisplayPanel;import org.javalib.util.TitledList;import JOscarLib.Management.Contact;import JOscarLib.Management.ContactList;/** * The <code>VisibilitySettingsPanel</code> class contains a panel with a * table for the visibility list. * @author Hansgeorg Schwibbe * @copyright 2004 */public class VisibilitySettingsPanel extends SettingsDisplayPanel{  private JScrollPane jScrollPaneTable = new JScrollPane();  private DefaultTableModel tableModel;  private TitledList localized = SettingsDialog.localized;  private JTable table;  private TableColumn tableColumn;  private IconTableCellRenderer renderer;  /**   * Initializes a new instance of the class   * <code>VisibilitySettingsPanel</code>.   */  public VisibilitySettingsPanel()  {    tableModel = new DefaultTableModel()    {      public boolean isCellEditable(int row, int column)      {        if (column == 0)        {          return false;        }        return true;      }    };    table = new JTable(tableModel);    table.getTableHeader().setReorderingAllowed(false);    Border innerBorder = BorderFactory.createEmptyBorder(12, 12, 12, 12);    Border outerBorder = BorderFactory.createEtchedBorder();    setBorder(BorderFactory.createCompoundBorder(innerBorder, outerBorder));    this.jScrollPaneTable.getViewport().add(table);    this.setLayout(new BorderLayout());    this.setBorder(BorderFactory.createLoweredBevelBorder());    this.add(jScrollPaneTable, BorderLayout.CENTER);  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#getContinueWithoutSavingMessage()   */  public String getContinueWithoutSavingMessage()  {    return ((String[]) localized.get("warningMessages"))[0] + "\n"           + ((String[]) localized.get("questionMessages"))[0];  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#getContinueWithoutSavingTitle()   */  public String getContinueWithoutSavingTitle()  {    return ((String[]) localized.get("messageTitles"))[2];  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#getListIconPath()   */  public String getListIconPath()  {    return Resource.ICON_SOURCE_SETTINGS[4];  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#getListName()   */  public String getListName()  {    return ((String[]) localized.get("settingsDialogList"))[4];  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#getSaveButtonText()   */  public String getSaveButtonText()  {    return ((String[]) localized.get("stdButtons"))[2] + " ("           + ((String[]) localized.get("settingsDialogList"))[4] + ")";  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#getSaveSettingsErrorTitle()   */  public String getSaveSettingsErrorTitle()  {    return ((String[]) localized.get("messageTitles"))[0];  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#hasChanged()   */  public boolean hasChanged()  {    Contact knownContact;    int count = table.getRowCount();    synchronized (Start.env)    {      for (int row = 0; row < count; row++)      {        knownContact = Start.env.getKnownList().get(row);        if ((((JRadioButton) table.getValueAt(row, 1)).isSelected() && knownContact.getIsInVisibleList() != true)            || (((JRadioButton) table.getValueAt(row, 3)).isSelected() && knownContact.getIsInInvisibleList() != true)            || (((JRadioButton) table.getValueAt(row, 2)).isSelected() && (knownContact.getIsInVisibleList() != false || knownContact.getIsInInvisibleList() != false)))        {          return true;        }      }    }    return false;  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#loadSettings()   */  public synchronized void loadSettings()  {    int row, clm, size;    String[] titles;    String title;    synchronized (Start.env)    {      size = Start.env.getKnownList().getContactListSize();      Object[][] data = new Object[size][3];      JRadioButton[][] radioButtons = new JRadioButton[size][3];      ButtonGroup[] buttonGroup = new ButtonGroup[size];      for (row = 0; row < size; row++)      {        radioButtons[row][0] = new JRadioButton();        radioButtons[row][0].addActionListener(new ActionListener()        {          public void actionPerformed(ActionEvent e)          {            table.repaint();          }        });        radioButtons[row][1] = new JRadioButton();        radioButtons[row][1].addActionListener(new ActionListener()        {          public void actionPerformed(ActionEvent e)          {            table.repaint();          }        });        radioButtons[row][2] = new JRadioButton();        radioButtons[row][2].addActionListener(new ActionListener()        {          public void actionPerformed(ActionEvent e)          {            table.repaint();          }        });        buttonGroup[row] = new ButtonGroup();        buttonGroup[row].add(radioButtons[row][0]);        buttonGroup[row].add(radioButtons[row][1]);        buttonGroup[row].add(radioButtons[row][2]);        Contact contact = Start.env.getKnownList().get(row);        if (contact.getIsInVisibleList() == true)        {          radioButtons[row][0].setSelected(true);        }        else if (contact.getIsInInvisibleList() == true)        {          radioButtons[row][2].setSelected(true);        }        else        {          radioButtons[row][1].setSelected(true);        }        data[row] = new Object[]        {         Start.env.getDisplayName(Start.env.getKnownList().get(row)),         radioButtons[row][0],         radioButtons[row][1],         radioButtons[row][2]        };      }      titles = ((String[]) localized.get("visibilitySettingsPanel"));      tableModel.setDataVector(data, titles);      title = ((String[]) localized.get("visibilitySettingsPanel"))[0];      tableColumn = table.getColumn(title);      renderer = new IconTableCellRenderer(Resource.VISIBILITY_IMG_SRC[0]);      renderer.setCellBorder(BorderFactory.createRaisedBevelBorder());      renderer.setCellHorizontalAlignment(SwingConstants.CENTER);      tableColumn.setHeaderRenderer(renderer);      renderer = new IconTableCellRenderer();      renderer.setCellBackground(table.getBackground());      tableColumn.setCellRenderer(renderer);      size = table.getColumnCount();      for (clm = 1; clm < size; clm++)      {        title = ((String[]) localized.get("visibilitySettingsPanel"))[clm];        tableColumn = table.getColumn(title);        renderer = new IconTableCellRenderer(Resource.VISIBILITY_IMG_SRC[clm]);        renderer.setCellBorder(BorderFactory.createRaisedBevelBorder());        renderer.setCellHorizontalAlignment(SwingConstants.CENTER);        tableColumn.setHeaderRenderer(renderer);        tableColumn.setCellRenderer(new RadioButtonTableCellRenderer());        tableColumn.setCellEditor(new RadioButtonCellEditor(new JCheckBox()));      }    }  }  /**   * (non-Javadoc)   * @see org.javalib.gui.model.SettingsDisplayPanel#saveSettings()   */  public synchronized void saveSettings() throws Exception  {    synchronized (Start.env)    {      if (Start.env.getConnection() == null          || !Start.env.getConnection().isLogged())      {        String msg = ((String[]) localized.get("errorMessages"))[16];        throw new Exception(msg);      }      ContactList updateList = new ContactList();      Contact contact;      int count = table.getRowCount();      for (int row = 0; row < count; row++)      {        contact = Start.env.getKnownList().get(row);        if (((JRadioButton) table.getValueAt(row, 1)).isSelected())        {          if (contact.getIsInVisibleList() && !contact.getIsInInvisibleList())          {            continue;          }          contact.setIsInVisibleList(true);          contact.setIsInInvisibleList(false);          updateList.addToContactList(contact);        }        else if (((JRadioButton) table.getValueAt(row, 3)).isSelected())        {          if (!contact.getIsInVisibleList() && contact.getIsInInvisibleList())          {            continue;          }          contact.setIsInVisibleList(false);          contact.setIsInInvisibleList(true);          updateList.addToContactList(contact);        }        else        {          if (!contact.getIsInVisibleList() && !contact.getIsInInvisibleList())          {            continue;          }          contact.setIsInVisibleList(false);          contact.setIsInInvisibleList(false);          updateList.addToContactList(contact);        }      }      int ownId = Integer.parseInt(Start.env.getOwnContact().getContactId());      new VisibilityBroadcast(Start.env.getConnection(), ownId, updateList);    }  }}

⌨️ 快捷键说明

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