📄 informationviewerdialog.java~
字号:
if (personal) enableAll(); wait.setVisible(false); validate(); setVisible(true); } }); } } private void addAboutItems() { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.add(about, BorderLayout.CENTER); fields.add(about); pane.add(new JScrollPane(panel), resources.getString("aboutUser")); } private void addWorkItems() { GridBagLayout grid = new GridBagLayout(); JPanel work = createNewPanel(grid); addItem(work, resources.getString("company"), company, grid); addItem(work, resources.getString("department"), department, grid); addItem(work, resources.getString("position"), position, grid); addItem(work, resources.getString("role"), role, grid); pane.add(work, resources.getString("work")); padEnd(work, grid); } private void addGeneralItems() { GridBagLayout grid = new GridBagLayout(); JPanel general = createNewPanel(grid); addItem(general, resources.getString("name"), name, grid); addItem(general, resources.getString("nickname"), nickname, grid); addItem(general, resources.getString("birthday"), birthday, grid); addItem(general, resources.getString("email"), email, grid); //addItem( general, resources.getString( "homepage" ), homepage, grid // ); addItem(general, resources.getString("phone"), phone, grid); pane.add(general, resources.getString("general")); padEnd(general, grid); } private void addLocationItems() { GridBagLayout grid = new GridBagLayout(); JPanel location = createNewPanel(grid); addItem(location, resources.getString("street"), street1, grid); //addItem( location, "", street2, grid ); addItem(location, resources.getString("city"), city, grid); addItem(location, resources.getString("state"), state, grid); addItem(location, resources.getString("zip"), zip, grid); addItem(location, resources.getString("country"), country, grid); pane.add(location, resources.getString("location")); padEnd(location, grid); } /** * Adds the different fields to the displayed form */ private void addClientItems() { GridBagLayout grid = new GridBagLayout(); JPanel client = createNewPanel(grid); /* gets jabber:iq:version information */ addItem(client, resources.getString("clientInformation"), clientField, grid); addItem(client, resources.getString("timeInformation"), timeField, grid); addItem(client, "Idle for", lastField, grid); pane.add(client, resources.getString("misc")); padEnd(client, grid); } private JPanel createNewPanel(GridBagLayout grid) { JPanel panel = new JPanel(grid); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.weighty = 0; c.anchor = GridBagConstraints.NORTHWEST; return panel; } private void disableAll() { for (int i = 0; i < fields.size(); i++) { JTextComponent field = (JTextComponent) fields.get(i); field.setEditable(false); } validate(); } private void enableAll() { for (int i = 0; i < fields.size(); i++) { JTextComponent field = (JTextComponent) fields.get(i); field.setEditable(true); } validate(); } private void padEnd(JPanel panel, GridBagLayout grid) { JLabel blank = new JLabel(""); c.gridwidth = 2; c.weighty = 1; grid.setConstraints(blank, c); panel.add(blank); } /** * Adds a field and starts the thread that will collect it's information * * @param key * the name of the field * @param informationThread * the thread that will collect the information */ private void addItem(JPanel panel, String l, MJTextField field, GridBagLayout grid) { c.fill = GridBagConstraints.HORIZONTAL; if (!l.equals("")) l = l + ": "; JLabel label = new JLabel(l); label.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 5)); c.ipadx = 2; c.ipady = 2; c.weightx = .1; c.gridx = 0; grid.setConstraints(label, c); panel.add(label); c.gridx++; c.weightx = 1; grid.setConstraints(field, c); panel.add(field); fields.add(field); c.gridy++; } public String getUser() { return user; }}/** * An <code>InformationCollector</code> that collects jabbber:iq:version * information * * @author Adam Olsen * @version 1.0 */class VersionCollector implements Runnable { InformationViewerDialog dialog; JTextField field; /** * The default constructor * * @param dialog * the InformationViewerDialog that called this thread * @param id * the field id */ public VersionCollector(MJTextField field, InformationViewerDialog dialog) { this.field = field; this.dialog = dialog; } /** * Called by the enclosing <code>java.util.Thread</code> The run() method * is responsible for collecting the requested information and setting the * field in the InformationViewerDialog */ public void run() { XMPPConnection con = BuddyList.getInstance().getConnection(); if( dialog.cancelled ) return; Version request = new Version(); request.setType(IQ.Type.GET); request.setTo(dialog.getUser()); // Create a packet collector to listen for a response. PacketCollector collector = con .createPacketCollector(new PacketIDFilter(request.getPacketID())); con.sendPacket(request); // Wait up to 5 seconds for a result. IQ result = (IQ) collector.nextResult(SmackConfiguration .getPacketReplyTimeout()); if( dialog.cancelled ) return; if (result != null && result.getType() == IQ.Type.RESULT) { Version v = (Version) result; field.setText(v.getName() + " " + v.getVersion() + " / " + v.getOs()); } else field.setText("N/A"); field.validate(); }}/** * @author Adam Olsen * @version 1.0 */class TimeCollector implements Runnable { InformationViewerDialog dialog; JTextField field; /** * The default constructor * * @param dialog * the InformationViewerDialog that called this thread * @param id * the field id */ public TimeCollector(MJTextField field, InformationViewerDialog dialog) { this.field = field; this.dialog = dialog; } /** * Called by the enclosing <code>java.util.Thread</code> The run() method * is responsible for collecting the requested information and setting the * field in the InformationViewerDialog */ public void run() { if( dialog.cancelled ) return; XMPPConnection con = BuddyList.getInstance().getConnection(); Time request = new Time(); request.setType(IQ.Type.GET); request.setTo(dialog.getUser()); // Create a packet collector to listen for a response. PacketCollector collector = con .createPacketCollector(new PacketIDFilter(request.getPacketID())); con.sendPacket(request); // Wait up to 5 seconds for a result. IQ result = (IQ) collector.nextResult(SmackConfiguration .getPacketReplyTimeout()); if( dialog.cancelled ) return; if (result != null && result.getType() == IQ.Type.RESULT) { Time t = (Time) result; field.setText(t.getDisplay()); } else field.setText("N/A"); field.validate(); }}class LastCollector implements Runnable { InformationViewerDialog dialog; JTextField field; /** * The default constructor * * @param dialog * the InformationViewerDialog that called this thread * @param id * the field id */ public LastCollector(MJTextField field, InformationViewerDialog dialog) { this.field = field; this.dialog = dialog; } /** * Called by the enclosing <code>java.util.Thread</code> The run() method * is responsible for collecting the requested information and setting the * field in the InformationViewerDialog */ public void run() { if( dialog.cancelled ) return; XMPPConnection con = BuddyList.getInstance().getConnection(); LastActivity request = new LastActivity(); request.setType(IQ.Type.GET); request.setTo(dialog.getUser()); // Create a packet collector to listen for a response. PacketCollector collector = con .createPacketCollector(new PacketIDFilter(request.getPacketID())); con.sendPacket(request); // Wait up to 5 seconds for a result. IQ result = (IQ) collector.nextResult(SmackConfiguration .getPacketReplyTimeout()); if( dialog.cancelled ) return; if (result != null && result.getType() == IQ.Type.RESULT) { LastActivity t = (LastActivity) result; field.setText(t.showTime()); } else field.setText("N/A"); field.validate(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -