📄 configdialog.java
字号:
}
listener.itemStateChanged(e);
}
public RouterPanel(ItemListener l,
String title,
String defaultName, String defaultPort,
boolean serverDefault, boolean routerDefault) {
super(title);
listener = l;
publicAddr = new HostPortPanel(this,
"Act as a relay (Both TCP and HTTP "
+ "must be enabled.)",
"Public address (static NAT address)",
defaultName,
defaultPort,
serverDefault);
remote = new HostListPanel(this,
"Use a relay "
+ "(Required if behind firewall/NAT)",
"Available relays",
routerDefault);
add(publicAddr, stdConstr);
add(remote, stdConstr);
}
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
helpLabel.setForeground(Color.black);
helpLabel.setText("See \"http://shell.jxta.org/index.html\" for config help");
}
public void itemStateChanged(ItemEvent e) {
boolean routerPossible =
( tcpPanel.getState()
&& httpPanel.getState());
// A remore router makes sense only if http is on.
routerPanel.remote.setEnabled(httpPanel.getState());
// Rendez-vous make sense only if their respective transports are on.
rdvPanel.http.setEnabled(httpPanel.getState());
rdvPanel.tcp.setEnabled(tcpPanel.getState());
// Can be a router only if both transports are on.
routerPanel.publicAddr.setEnabled(routerPossible);
// A proxy does not make sense if there's no router.
if (httpPanel.getState()) {
idPanel.proxyPanel.setEnabled(routerPanel.remote.getState());
}
}
public ConfigDialog(PeerAdvertisement cadv){
super("JXTA Configurator");
stdConstr = new GridBagConstraints();
stdConstr.gridwidth = GridBagConstraints.REMAINDER;
stdConstr.gridheight = 1;
stdConstr.gridx = 0;
stdConstr.gridy = GridBagConstraints.RELATIVE;
stdConstr.fill = GridBagConstraints.NONE;
stdConstr.weightx = 1;
stdConstr.anchor = GridBagConstraints.NORTHWEST;
stdConstr.insets = new Insets(0,0,0,0);
fillConstr = (GridBagConstraints) stdConstr.clone();
fillConstr.fill = GridBagConstraints.HORIZONTAL;
centerConstr = (GridBagConstraints) stdConstr.clone();
centerConstr.anchor = GridBagConstraints.NORTH;
centerLastConstr = (GridBagConstraints) centerConstr.clone();
centerLastConstr.weighty = 1;
midLineConstr = new GridBagConstraints();
midLineConstr.gridwidth = 1;
midLineConstr.gridheight = 1;
midLineConstr.fill = GridBagConstraints.NONE;
midLineConstr.anchor = GridBagConstraints.EAST;
midLineConstr.weightx = 0;
midLineEastConstr = (GridBagConstraints) midLineConstr.clone();
midLineEastConstr.anchor = GridBagConstraints.EAST;
midLineEastConstr.weightx = 1;
rightLineConstr = (GridBagConstraints) midLineConstr.clone();
rightLineConstr.gridwidth = GridBagConstraints.REMAINDER;
rightLineConstr.weightx = 1;
rightLineConstr.anchor = GridBagConstraints.WEST;
leftLineConstr = (GridBagConstraints) midLineConstr.clone();
leftLineConstr.gridx = 0;
leftLineConstr.weightx = 0;
leftLineConstr.anchor = GridBagConstraints.WEST;
leftLineConstr.insets = new Insets(0,20, 0, 20);
GridBagConstraints fillInsetConstr =
(GridBagConstraints)fillConstr.clone();
fillInsetConstr.insets = new Insets(5,5,5,5);
leftPanelConstr = (GridBagConstraints)fillConstr.clone();
leftPanelConstr.gridwidth = 1;
rightPanelConstr = (GridBagConstraints)fillConstr.clone();
rightPanelConstr.gridwidth = GridBagConstraints.REMAINDER;;
rightPanelConstr.gridx = GridBagConstraints.RELATIVE;
configAdv = cadv;
String dftDebugLevel = configAdv.getDebugLevel();
boolean isRendezvous = false;
Vector rdvs = new Vector();
try {
TextElement param = (TextElement)
configAdv.getServiceParam(PeerGroup.rendezvousClassID);
if (param != null) {
Enumeration rdvEnum = param.getChildren("Addr");
while (rdvEnum.hasMoreElements()) {
rdvs.addElement( ( (TextElement)
rdvEnum.nextElement() ).getTextValue() );
}
Enumeration rdv = param.getChildren("Rdv");
isRendezvous =
rdv.hasMoreElements()
&& "true".equals(((TextElement) rdv.nextElement()).getTextValue());
}
} catch (Exception nobigdeal) {
nobigdeal.printStackTrace();
}
boolean tcpDefault = true;
boolean httpDefault = true;
try {
Element param =
configAdv.getServiceParam(PeerGroup.httpProtoClassID);
if (param.getChildren("isOff").hasMoreElements()) {
httpDefault = false;
}
// FIXME 20011220 bondolo@jxta.org Temporarily accept both nodes of
// type HTTPAdv and TransportAdvertisement.
Enumeration httpChilds = param.getChildren(
TransportAdvertisement.getAdvertisementType());
// get the TransportAdv from either TransportAdv or HttpAdv
if( httpChilds.hasMoreElements() ) {
param = (Element) httpChilds.nextElement();
} else {
httpChilds = param.getChildren(
HTTPAdv.getAdvertisementType());
if( httpChilds.hasMoreElements() ) {
param = (Element) httpChilds.nextElement();
}
}
httpAdv = (HTTPAdv)
AdvertisementFactory.newAdvertisement((TextElement) param);
} catch (Exception thatsbad) {
thatsbad.printStackTrace();
throw new RuntimeException("Broken PeerAdvertisement. Cannot proceed.");
}
try {
Element param =
configAdv.getServiceParam(PeerGroup.tcpProtoClassID);
if (param.getChildren("isOff").hasMoreElements()) {
tcpDefault = false;
}
// FIXME 20011220 bondolo@jxta.org Temporarily accept both nodes of
// type TCPAdv and TransportAdvertisement.
Enumeration tcpChilds = param.getChildren(
TransportAdvertisement.getAdvertisementType());
// get the TransportAdv from either TransportAdv or HttpAdv
if( tcpChilds.hasMoreElements() ) {
param = (Element) tcpChilds.nextElement();
} else {
tcpChilds = param.getChildren(
TCPAdv.getAdvertisementType());
if( tcpChilds.hasMoreElements() ) {
param = (Element) tcpChilds.nextElement();
}
}
tcpAdv = (TCPAdv)
AdvertisementFactory.newAdvertisement((TextElement) param);
} catch (Exception thatsbad2) {
thatsbad2.printStackTrace();
throw new RuntimeException("Broken PeerAdvertisement. Cannot proceed.");
}
// Read-in the adv as it is now.
boolean serverDefault = httpAdv.getServerEnabled();
boolean proxyDefault = httpAdv.getProxyEnabled();
boolean routerDefault = httpAdv.getRouterEnabled();
String defaultServerNameH = httpAdv.getServer();
String defaultProxyName = httpAdv.getProxy();
Vector defaultRouters = httpAdv.getRouters();
String defaultInterfaceAddressH = httpAdv.getInterfaceAddress();
String configModeH = httpAdv.getConfigMode();
String defaultServerNameT = tcpAdv.getServer();
String defaultInterfaceAddressT = tcpAdv.getInterfaceAddress();
String configModeT = tcpAdv.getConfigMode();
boolean prefAlwaysManualH = true;
boolean prefAlwaysManualT = true;
// Looks funny but that's the way it is. True is the default
// which applies in auto or default mode as well if alwaysManual
// is set explicitly. Only when "manual" is set do we set the
// preference to false. configMode controls other things
// than just this preference.
if ( (configModeH != null)
&& (configModeH.equals("manual"))) {
prefAlwaysManualH = false;
}
if ( (configModeT != null)
&& (configModeT.equals("manual"))) {
prefAlwaysManualT = false;
}
int index;
String defaultProxyPort = "8080";
String defaultServerPortH = "9700";
String defaultPortH = httpAdv.getPort();
String defaultServerPortT = "9701";
String defaultPortT = tcpAdv.getPort();
if ( defaultProxyName != null ) {
index = defaultProxyName.indexOf(":");
defaultProxyPort = defaultProxyName.substring(index + 1);
defaultProxyName = defaultProxyName.substring(0, index);
}
if (defaultServerNameH != null
&& (index = defaultServerNameH.indexOf(":")) != -1) {
defaultServerPortH = defaultServerNameH.substring(index + 1);
defaultServerNameH = defaultServerNameH.substring(0, index);
} else {
defaultServerNameH = "";
defaultServerPortH = "9700";
}
if (defaultServerNameT != null
&& (index = defaultServerNameT.indexOf(":")) != -1) {
defaultServerPortT = defaultServerNameT.substring(index + 1);
defaultServerNameT = defaultServerNameT.substring(0, index);
} else {
defaultServerNameT = "";
defaultServerPortT = "9701";
}
if ( (defaultPortT == null)
|| defaultPortT.equals("") ) {
defaultPortT = "9701";
}
if ( (defaultPortH == null)
|| defaultPortH.equals("") ) {
defaultPortH = "9700";
}
String pn = configAdv.getName();
helpLabel = new Label("See \"http://shell.jxta.org/index.html\" for config help", Label.CENTER);
helpLabel.setBackground(new Color(220, 220, 220));
helpLabel.setForeground(Color.black);
idPanel = new IdPanel(pn,
defaultProxyName,
defaultProxyPort,
proxyDefault);
debugPanel = new DebugPanel(dftDebugLevel);
tcpPanel = new TcpPanel(this,
defaultInterfaceAddressT,
defaultPortT,
defaultServerNameT,
defaultServerPortT,
tcpDefault,
prefAlwaysManualT);
httpPanel = new HttpPanel(this,
defaultInterfaceAddressH,
defaultPortH,
httpDefault,
prefAlwaysManualH
);
routerPanel = new RouterPanel(this, "HTTP Relay Settings",
defaultServerNameH,
defaultServerPortH,
serverDefault,
routerDefault);
// If security is already in place, then the security
// panel is disabled. A user can only define the
// principal role one time.
//
// We check to see if we will configure TLS now.
if (TlsConfig.willConfigureTls()) {
// Use initial panel
secPanel = new SecPanel(true);
} else {
// Use explanation panel(Nothing to do)
secPanel = new SecPanel(false);
}
if (defaultRouters != null) {
Enumeration e = defaultRouters.elements();
while (e.hasMoreElements()) {
routerPanel.remote.addItem((String) e.nextElement());
}
}
rdvPanel = new RdvPanel("Rendezvous Settings",
isRendezvous);
if (rdvs != null) {
Enumeration e = rdvs.elements();
while (e.hasMoreElements()) {
String s = (String) e.nextElement();
if (s.startsWith("tcp://")) {
rdvPanel.tcp.addItem(s.substring(6));
continue;
}
if (s.startsWith("http://")) {
rdvPanel.http.addItem(s.substring(7));
}
}
}
ok = new Button(" OK ");
cancel = new Button("Cancel");
routerPanel.remote.setEnabled(httpPanel.getState());
routerPanel.publicAddr.setEnabled( tcpPanel.getState()
&& httpPanel.getState());
rdvPanel.http.setEnabled(httpPanel.getState());
rdvPanel.tcp.setEnabled(tcpPanel.getState());
Panel okPanel = new Panel();
okPanel.add(ok);
okPanel.add(cancel);
PanelGBL basicsPanel = pages.addPage("basic",
"Basic settings");
PanelGBL advancedPanel = pages.addPage("advanced",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -