/** * Returns an ImageIcon, or null if the path was invalid. When running an applet using Java * Plug-in, getResourceAsStream is more efficient than getResource. * * @param path the path to the image icon * @param description a text description of the image * @return a new ImageIcon or null if the image could not be loaded from the specified path */ protected static ImageIcon createAppletImageIcon(String path, String description) { int MAX_IMAGE_SIZE = 575000; // Change this to the size of // your biggest image, in bytes. int count = 0; BufferedInputStream imgStream = new BufferedInputStream(Folder.class.getResourceAsStream(path)); if (imgStream != null) { byte buf[] = new byte[MAX_IMAGE_SIZE]; try { count = imgStream.read(buf); } catch (IOException ieo) { LOG.error(Messages.getString(BUNDLE_NAME, "Folder.29") + path); // $NON-NLS-1$ LOG.error(ieo.getLocalizedMessage()); } try { imgStream.close(); } catch (IOException ieo) { LOG.error(Messages.getString(BUNDLE_NAME, "Folder.30") + path); // $NON-NLS-1$ } if (count <= 0) { LOG.error(Messages.getString(BUNDLE_NAME, "Folder.31") + path); // $NON-NLS-1$ return null; } return new ImageIcon(Toolkit.getDefaultToolkit().createImage(buf), description); } else { LOG.error(Messages.getString(BUNDLE_NAME, "Folder.32") + path); // $NON-NLS-1$ return null; } }
/** * Read the description of the Folder from the specified URL. * * @param url the URL of a web service providing the description of the Folder * @param treenode the JTree node that represents this Folder */ private void readFolderFromURL(String url, DefaultMutableTreeNode treenode) { ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); // add the LoadDescription action list.add(new NameValuePair("Action", "LoadDescription")); // $NON-NLS-1$ //$NON-NLS-2$ try { // get an input stream from the URL InputStream fin = getInputStream(url, list); // build the XML document SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(fin); // get the root Element in the document Element root = doc.getRootElement(); readFolder(treenode, root); } catch (MalformedURLException ex) { errorMessage(Messages.getString(BUNDLE_NAME, "Folder.12") + url); // $NON-NLS-1$ LOG.error(Messages.getString(BUNDLE_NAME, "Folder.13") + url, ex); // $NON-NLS-1$ } catch (JDOMException ex) { // indicates a well-formedness error errorMessage(Messages.getString(BUNDLE_NAME, "Folder.14") + url); // $NON-NLS-1$ LOG.error(Messages.getString(BUNDLE_NAME, "Folder.15") + url, ex); // $NON-NLS-1$ } catch (IOException ex) { errorMessage(Messages.getString(BUNDLE_NAME, "Folder.16") + url); // $NON-NLS-1$ LOG.error(Messages.getString(BUNDLE_NAME, "Folder.17") + url, ex); // $NON-NLS-1$ } catch (Exception ex) { errorMessage(Messages.getString(BUNDLE_NAME, "Folder.18") + url); // $NON-NLS-1$ LOG.error(Messages.getString(BUNDLE_NAME, "Folder.19") + url, ex); // $NON-NLS-1$ } }
public void loadData(ArrayList<NameValuePair> params, String action) { if (loaded) { return; } if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.26")); // $NON-NLS-1$ } // tell the tabs in this folder to load their data for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); if (item == null) { LOG.error(name + Messages.getString(BUNDLE_NAME, "Folder.27") + getTitle()); // $NON-NLS-1$ continue; } if (LOG.isDebugEnabled()) { LOG.debug( name + Messages.getString(BUNDLE_NAME, "Folder.28") + item.getTitle()); // $NON-NLS-1$ } item.loadData(params, action); } loaded = true; }
/* (non-Javadoc) * @see org.ribax.swing.ui.TabContainer#loadItemData(java.util.ArrayList, java.lang.String) */ protected void loadItemData(ArrayList<NameValuePair> params, String action) { if (params == null) { params = new ArrayList<NameValuePair>(); } // if there are parameters on this Tab then add them to the parameters for // submission to any web service if (paramSet != null) { ArrayList<NameValuePair> tlist = paramSet.getNameValuePairs(); if (tlist != null) { params.addAll(tlist); } } if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Tab.19")); // $NON-NLS-1$ } // tell each data Item to load its data using the parameters and action string for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); if (item == null) { LOG.error(name + Messages.getString(BUNDLE_NAME, "Tab.20") + getTitle()); // $NON-NLS-1$ continue; } item.loadData(params, action); } }
/* (non-Javadoc) * @see org.ribax.swing.ui.TabContainer#refresh(java.util.ArrayList, java.lang.String) */ public void refresh(ArrayList<NameValuePair> params, String action) { if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Tab.17")); // $NON-NLS-1$ } // invalidate all the DataItems on this Tab invalidateDataItems(); if (source != null) { // replace the contents of the tab with the data from the source readDescriptionFromURL(url, params, action); loaded = false; // now tell each new data item to load its data loadData(params, action); } else { // tell each DataItem in our internal list to refresh for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); if (item == null) { LOG.error(name + Messages.getString(BUNDLE_NAME, "Tab.18") + getTitle()); // $NON-NLS-1$ continue; } item.refresh(params, action); } } }
/** * Read the definition of this Folder from the XML element tree. * * @param treenode the JTree node that represents this Folder * @param node the XML element tree */ public void readFolder(DefaultMutableTreeNode treenode, Element node) { Element e; String source = null; // base class reads common values super.readDescription(node); // get the heading heading = XMLutils.getElementString("heading", node); // $NON-NLS-1$ // if a background colour has been specified then set it also for the tabbed pane if (bgcolour != null) { tabbedPane.setBackground(bgcolour); } source = XMLutils.getElementString("source", node); // $NON-NLS-1$ // if a source has been specified then read the description from the source // test the value of url, if it has been set then this could be the 2nd // time we are in this method, a source tag in a sourced description would // otherwise cause an infinite loop if (source != null && url == null) { url = source; readFolderFromURL(source, treenode); return; } // read the list of tabs in this folder if ((e = node.getChild("tabList")) != null) { // $NON-NLS-1$ if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.4")); // $NON-NLS-1$ } // iterate through the list List<Element> children = e.getChildren(); Iterator<Element> iterator = children.iterator(); while (iterator.hasNext()) { Element tabnode = (Element) iterator.next(); // create a new Tab and read the definition Tab t = new Tab(this); t.readDescription(tabnode); // add the tab to this folder addDataItem(t); } } Element tds; // get any tabbed data sets // Tabbed data sets are siblings of other tabs in the tabbed pane and are // themselves a tabbed pane with a set of sub tabs if ((tds = node.getChild("tabbedDataSet")) != null) { // $NON-NLS-1$ if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.6")); // $NON-NLS-1$ } // create a new tabbed data set TabbedDataSet tabset = new TabbedDataSet(this); // read the description and add it to the tabbed pane tabset.bgcolour = bgcolour; tabset.readDescription(tds); addDataItem(tabset); } // read any sub folders recursively if ((e = node.getChild("folderList")) != null) { // $NON-NLS-1$ if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.8")); // $NON-NLS-1$ } // iterate through the list of folders List<Element> children = e.getChildren(); Iterator<Element> iterator = children.iterator(); while (iterator.hasNext()) { Element folder = (Element) iterator.next(); // create a new Folder Folder f = new Folder(this); DefaultMutableTreeNode newnode = new DefaultMutableTreeNode(f); // read the description of the folder and add it to the JTree // as a child of the tree node that this Folder represents f.readFolder(newnode, folder); treenode.add(newnode); } } layoutComponents(); // get any specified icon try { String logo = XMLutils.getElementString("icon", node); // $NON-NLS-1$ if (logo != null) { URL u = new URL(logo); this.icon = new ImageIcon(u); // createAppletImageIcon(logo,title); } } catch (Exception ex) { LOG.error(name, ex); } }