/** * Called when a new selection is made in the service finder. * * @param e */ @Override public void valueChanged(ListSelectionEvent e) { FoundService f = list.getSelectedValue(); if (f != null) { setEntryText("Host", f.getHost().getHostAddress()); setEntryText("Name", String.valueOf(f.getId())); setSelectedRadio("Network"); } else { setEntryText("Host", ""); setEntryText("Name", ""); } }
/** * Create the dialog * * @param fileDefault a possible default for the file database * @param netDefault a possible default for the URL database * @param defaultnetwork whether to default to the network radio or not */ public DatabaseDialog(String fileDefault, String netDefault, boolean defaultnetwork) { super(new MigLayout(""), false); JButton chooserOpen = new JButton("..."); chooserOpen.addActionListener(this); if (fileDefault != null) { if (netDefault != null) mainPanel.add(radio("File")); else radio("File"); mainPanel.add(entry("File", fileDefault), "wmin 200, spanx 2, grow"); mainPanel.add(chooserOpen, "wrap"); if (netDefault != null) mainPanel.add(label("", false), "hmin 20, wrap"); } if (netDefault != null) { String split[] = netDefault.split("/"); if (fileDefault != null) mainPanel.add(radio("Network"), "spany 2"); else radio("Network"); mainPanel.add(label("Host", false), ""); mainPanel.add(entry("Host", split.length > 0 ? split[0] : ""), "wmin 200, grow, wrap"); mainPanel.add(label("Name", false), ""); mainPanel.add(entry("Name", split.length > 1 ? split[1] : ""), "grow, wrap"); try { list = new JServiceList(); list.addListSelectionListener(this); JScrollPane scroll = new JScrollPane(list); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); finder = new ServiceFinder("RemoteDatabase"); finder.addListener(list); finder.start(); mainPanel.add(scroll, "w 300, h 400, spanx 2, skip, wrap"); } catch (Exception e) { mainPanel.add(label("Unabled to start ServiceFinder: " + e.getMessage(), false), ""); } } result = null; if ((netDefault != null) && (fileDefault != null)) setSelectedRadio(defaultnetwork ? "Network" : "File"); else if (fileDefault == null) setSelectedRadio("Network"); else setSelectedRadio("File"); }