📄 addressselection.java
字号:
package net.java.mais.gui.config.xml;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import net.java.mais.common.PropertiesDepot;
import net.java.mais.plugin.addressselector.NetworkAddressSelector;
/**
* <p>Title: Netsite TudoMais</p>
* <p>Description:JAIN-SIP Audio/Video phone application</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Organisation: CTBC Telecom / Netsite </p>
* @author Thiago Rocha Camargo (barata7@yahoo.com)
*/
public class AddressSelection extends JDialog {
JTree addressTree;
JScrollPane treePane = new JScrollPane();
Action actionOk = new AbstractAction("OK") {
// This method is called when the button is pressed
public void actionPerformed(ActionEvent evt) {
setProperties();
close();
}
};
JButton bOk = new JButton(actionOk);
public AddressSelection(){
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
setProperties();
}
});
try{
addressTree = NetworkAddressSelector.createAddressTree();
NetworkAddressSelector.preselectAddress(addressTree);
Enumeration localIfaces = NetworkInterface.getNetworkInterfaces();
int leafs=0;
for(leafs=-1;localIfaces.hasMoreElements();leafs++,localIfaces.nextElement());
if(leafs==0){
this.close();
return;
}else if(leafs<=0){
this.close();
// JOptionPane.showMessageDialog(parent.phoneFrame,"N鉶 existe nenhuma conex鉶 dispon韛el!","Erro de conex鉶",JOptionPane.ERROR_MESSAGE);
// parent.fireExitRequest();
return;
}
}catch(IOException e){
this.close();
}
// GUI
treePane.setViewportView(addressTree);
treePane.getViewport().setBackground(Color.white);
treePane.setMaximumSize(new Dimension(220, 150));
treePane.setMinimumSize(new Dimension(220, 150));
treePane.setPreferredSize(new Dimension(220, 150));
this.setTitle("Selecione a conex鉶");
this.getContentPane().add(treePane,BorderLayout.CENTER);
this.getContentPane().add(bOk,BorderLayout.SOUTH);
this.pack();
this.centerWindow();
this.setResizable(false);
this.setVisible(true);
}
public void setProperties(){
TreePath selectionPath = addressTree.getSelectionPath();
if (selectionPath != null && selectionPath.getPathCount() == 3) {
DefaultMutableTreeNode addrNode = (DefaultMutableTreeNode)selectionPath.getPathComponent(2);
InetAddress selectedAddress = (InetAddress) addrNode.getUserObject();
DefaultMutableTreeNode ifaceNode = (DefaultMutableTreeNode)selectionPath.getPathComponent(1);
NetworkInterface selectedInterface = (NetworkInterface) ifaceNode.getUserObject();
PropertiesDepot.setProperty("net.java.mais.common.PREFERRED_NETWORK_ADDRESS", selectedAddress.getHostAddress() );
PropertiesDepot.setProperty("net.java.mais.common.PREFERRED_NETWORK_INTERFACE", selectedInterface.getDisplayName() );
PropertiesDepot.storeProperties();
}
}
private void centerWindow()
{
Rectangle screen = new Rectangle(
Toolkit.getDefaultToolkit().getScreenSize());
Point center = new Point(
(int) screen.getCenterX(), (int) screen.getCenterY());
Point newLocation = new Point(
center.x - this.getWidth() / 2, center.y - this.getHeight() / 2);
if (screen.contains(newLocation.x, newLocation.y,
this.getWidth(), this.getHeight())) {
this.setLocation(newLocation);
}
}
public void close(){
this.setVisible(false);
this.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -