BrowserApp.java revision 4b22b9337f359bfd063322244f5336cc7c6ffcfa
/* -*- Mode: Java; tab-width: 4 -*-
*
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
* ("Apple") in consideration of your agreement to the following terms, and your
* use, installation, modification or redistribution of this Apple software
* constitutes acceptance of these terms. If you do not agree with these terms,
* please do not use, install, modify or redistribute this Apple software.
*
* In consideration of your agreement to abide by the following terms, and subject
* to these terms, Apple grants you a personal, non-exclusive license, under Apple's
* copyrights in this original Apple software (the "Apple Software"), to use,
* reproduce, modify and redistribute the Apple Software, with or without
* the Apple Software in its entirety and without modifications, you must retain
* this notice and the following text and disclaimers in all such redistributions of
* the Apple Software. Neither the name, trademarks, service marks or logos of
* Apple Computer, Inc. may be used to endorse or promote products derived from the
* Apple Software without specific prior written permission from Apple. Except as
* expressly stated in this notice, no other rights or licenses, express or implied,
* are granted by Apple herein, including but not limited to any patent rights that
* may be infringed by your derivative works or by other works in which the Apple
* Software may be incorporated.
*
* The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
* COMBINATION WITH YOUR PRODUCTS.
*
* IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
* (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
BrowserApp demonstrates how to use DNS-SD to browse for and resolve services.
To do:
- display resolved TXTRecord
ident "%Z%%M% %I% %E% SMI"
*/
{
static BrowserApp app;
public BrowserApp()
{
});
domainList = new DomainListModel();
servicesList = new ServicesBrowserListModel();
serviceList = new BrowserListModel();
try {
}
frame.setVisible(true);
}
{
domainPane.addListSelectionListener( this);
JScrollPane domainScroller = new JScrollPane( domainPane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
servicesPane.addListSelectionListener( this);
JScrollPane servicesScroller = new JScrollPane( servicesPane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
servicePane.addListSelectionListener( this);
JScrollPane serviceScroller = new JScrollPane( servicePane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
/*
JPanel buttonRow = new JPanel();
buttonRow.setLayout( new BoxLayout( buttonRow, BoxLayout.X_AXIS));
buttonRow.add( Box.createHorizontalGlue());
JButton connectButton = new JButton( "Don't Connect");
buttonRow.add( connectButton);
buttonRow.add( Box.createRigidArea( new Dimension( 16, 0)));
*/
// parent.add( buttonRow);
}
public void valueChanged( ListSelectionEvent e)
{
try {
{
if ( -1 != newSel)
{
if ( serviceBrowser != null)
}
}
{
if ( serviceBrowser != null)
if ( -1 != newSel)
}
{
if ( -1 != newSel)
{
new SwingResolveListener( this));
}
}
}
}
{
}
{
// handle failure here
}
protected static void terminateWithException( Exception e)
{
e.printStackTrace();
}
{
app = new BrowserApp();
}
}
{
public BrowserListModel()
{
removeCache = new Vector();
}
/* The Browser invokes this callback when a service is discovered. */
{
this.scheduleOnEventThread();
}
{
this.scheduleOnEventThread();
}
public void run()
{
{
if ( matchInd != -1)
this.removeElementAt( matchInd);
}
{
this.addInSortOrder( elem);
}
}
{
// handle failure here
}
/* The list contains BrowserListElem's */
class BrowserListElem
{
public int fInt;
}
public String getNthServiceName( int n)
{
return sel.fServiceName;
}
public String getNthRegType( int n)
{
}
public String getNthDomain( int n)
{
}
public int getNthInterface( int n)
{
}
{
int i;
for ( i = 0; i < this.size(); i++)
break;
}
{
for ( int i = 0; i < this.size(); i++)
return i;
return -1;
}
protected void scheduleOnEventThread()
{
try {
SwingUtilities.invokeAndWait( this);
}
catch ( Exception e)
{
e.printStackTrace();
}
}
static // Initialize our static variables
{
}
}
class ServicesBrowserListModel extends BrowserListModel
{
/* The Browser invokes this callback when a service is discovered. */
// Overridden to stuff serviceName into regType and make serviceName human-readable.
{
}
// Overridden to make serviceName human-readable.
{
}
// Convert a registration type into a human-readable string. Returns original string on no-match.
{
final String[] namedServices = {
"_afpovertcp", "Apple File Sharing",
"_http", "World Wide Web servers",
"_daap", "Digital Audio Access",
"_apple-sasl", "Apple Password Servers",
"_distcc", "Distributed Compiler nodes",
"_finger", "Finger servers",
"_ichat", "iChat clients",
"_presence", "iChat AV clients",
"_ssh", "SSH servers",
"_telnet", "Telnet servers",
"_workstation", "Macintosh Manager clients",
"_bootps", "BootP servers",
"_xserveraid", "XServe RAID devices",
"_eppc", "Remote AppleEvents",
"_ftp", "FTP services",
"_tftp", "TFTP services"
};
return namedServices[i + 1];
return type;
}
}
{
/* Called when a domain is discovered. */
{
this.addElement( domain);
}
{
this.removeElement( domain);
}
{
// handle failure here
}
}