示例#1
0
  /**
   * 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;
    }
  }
示例#2
0
  /**
   * 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$
    }
  }
示例#3
0
  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;
  }
示例#4
0
  /** Layout the GUI components of this Folder. */
  private void layoutComponents() {

    // clear the box
    box.removeAll();

    // add the heading if one has been specified
    if (heading != null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug(Messages.getString(BUNDLE_NAME, "Folder.0")); // $NON-NLS-1$
      }
      JLabel p1 = new JLabel(heading);
      box.add(p1);
    }

    // add the tabbed pane if there is more than 1 tab
    if (dataItems.size() > 1) {
      box.add(tabbedPane);

    } else if (dataItems.size() == 1) {
      // otherwise add the single tab as the main component
      DataItem item = (DataItem) dataItems.elementAt(0);
      box.add(item);
    }

    validate();

    repaint();
  }
示例#5
0
文件: Tab.java 项目: damianham/RIBAX
  /* (non-Javadoc)
   * @see org.ribax.swing.ui.TabContainer#loadData(java.util.ArrayList, java.lang.String)
   */
  public void loadData(ArrayList<NameValuePair> params, String action) {

    // if we already have our data then do nothing
    if (loaded) {
      return;
    }

    try {
      setCursor(new Cursor(Cursor.WAIT_CURSOR));

      // if we have deferred reading the Tab description until the Tab was displayed
      // then read the description now
      if (deferredSource != null) {
        readDescriptionFromURL(deferredSource, deferredParams, deferredAction);
        deferredSource = null;
        deferredParams = null;
        deferredAction = null;
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug(name + Messages.getString(BUNDLE_NAME, "Tab.23")); // $NON-NLS-1$
      }
      // load the data for all the DataItems on this Tab
      loadItemData(params, action);
    } finally {
      // whatever happens we must set the cursor back to the default
      setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }

    // indicate we have loaded our data
    loaded = true;
  }
示例#6
0
文件: Tab.java 项目: damianham/RIBAX
  /* (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);
    }
  }
示例#7
0
文件: Tab.java 项目: damianham/RIBAX
  /* (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);
      }
    }
  }
示例#8
0
 /* (non-Javadoc)
  * @see org.ribax.swing.ui.DataItem#updateData(java.util.ArrayList, java.lang.String)
  */
 public void updateData(ArrayList<NameValuePair> params, String action) {
   if (LOG.isDebugEnabled()) {
     LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.25")); // $NON-NLS-1$
   }
   // update all the Tabs in this folder
   for (int i = 0; i < dataItems.size(); i++) {
     DataItem item = (DataItem) dataItems.elementAt(i);
     item.updateData(params, action);
   }
 }
示例#9
0
  /* (non-Javadoc)
   * @see org.ribax.swing.ui.DataItem#refresh(java.util.ArrayList, java.lang.String)
   */
  public void refresh(ArrayList<NameValuePair> params, String action) {
    if (LOG.isDebugEnabled()) {
      LOG.debug(name + " refresh");
    }

    // refresh each Tab in the tabbed pane
    for (int i = 0; i < dataItems.size(); i++) {
      DataItem item = (DataItem) dataItems.elementAt(i);
      item.refresh(params, action);
    }
  }
示例#10
0
  /* (non-Javadoc)
   * @see org.ribax.swing.ui.DataItem#invalidateData()
   */
  public void invalidateData() {
    if (LOG.isDebugEnabled()) {
      LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.24")); // $NON-NLS-1$
    }
    loaded = false;

    // invalidate all the Tabs in this folder
    for (int i = 0; i < dataItems.size(); i++) {
      DataItem item = (DataItem) dataItems.elementAt(i);
      item.invalidateData();
    }
  }
示例#11
0
 /**
  * Add a component to the tabbed pane.
  *
  * @param item the component to add.
  */
 protected void addDataItem(DataItem item) {
   if (LOG.isDebugEnabled()) {
     LOG.debug(
         name
             + Messages.getString(BUNDLE_NAME, "Folder.20")
             + item.getDataItemName()
             + Messages.getString(BUNDLE_NAME, "Folder.21")); // $NON-NLS-1$ //$NON-NLS-2$
   }
   item.setBorder(new EmptyBorder(5, 5, 5, 5));
   dataItems.add(item);
   String title = item.getTitle();
   if (title == null || title.length() == 0) {
     title = item.toString();
   }
   tabbedPane.addTab(title, item);
 }
示例#12
0
文件: Tab.java 项目: damianham/RIBAX
  /* (non-Javadoc)
   * @see org.ribax.swing.ui.TabContainer#readDescription(org.jdom.Element)
   */
  public void readDescription(Element tab) {
    Element e;

    super.readDescription(tab);

    box.removeAll();

    if (LOG.isDebugEnabled()) {
      LOG.debug(name + Messages.getString(BUNDLE_NAME, "Tab.2")); // $NON-NLS-1$
    }
    // get the set of DataItems on this Tab
    if ((e = tab.getChild("dataItems")) != null) { // $NON-NLS-1$
      if (LOG.isDebugEnabled()) {
        LOG.debug(name + Messages.getString(BUNDLE_NAME, "Tab.7")); // $NON-NLS-1$
      }
      // iterate through the DataItems
      List<Element> dilist = e.getChildren();
      Iterator<Element> it = dilist.iterator();
      while (it.hasNext()) {
        Element di = it.next();

        // use DataItemFactory.readComponent to create a new DataItem
        // from the Element tree
        DataItem component = DataItemFactory.readComponent(di, this);

        if (component == null) {
          continue;
        }

        // if the DataItem is hidden then only add it to our internal list
        if (component instanceof HiddenDataItem) {
          dataItems.add(component);
        } else // otherwise add it to our internal list and the display panel
        {
          addDataItem(component);
        }
      }
    }

    // layout the GUI components
    layoutComponents();
  }
示例#13
0
  /**
   * 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);
    }
  }
示例#14
0
  /**
   * Load the given Folder into the main panel.
   *
   * @param node the user object from the JTree node that should be a Folder/DataItem
   * @see org.ribax.swing.ui.Folder
   * @see org.ribax.swing.ui.DataItem
   */
  private void loadNodeObject(Object node) {

    if (node == null) {
      return;
    }

    try {
      setCursor(new Cursor(Cursor.WAIT_CURSOR));

      this.nodeInfo = node;

      if (LOG.isDebugEnabled()) {
        LOG.debug(
            name
                + Messages.getString(BUNDLE_NAME, "RootFolder.13")
                + nodeInfo.toString()); // $NON-NLS-1$
      }
      // the node object must be a DataItem
      if (nodeInfo instanceof DataItem) {

        // get the name or title of the Folder/DataItem
        String nodeName = ((DataItem) nodeInfo).getDataItemName();
        if (nodeName == null) {
          nodeName = ((DataItem) nodeInfo).getTitle();
        }

        applet.reportStatus(
            name
                + Messages.getString(BUNDLE_NAME, "RootFolder.14")
                + nodeName
                + Messages.getString(BUNDLE_NAME, "RootFolder.15")); // $NON-NLS-1$ //$NON-NLS-2$

        // tell the Folder to load it's data if it hasn't already done so
        if (globalParams == null) {
          ((DataItem) nodeInfo)
              .loadData(null, Messages.getString(BUNDLE_NAME, "RootFolder.16")); // $NON-NLS-1$
        } else {
          ((DataItem) nodeInfo)
              .loadData(globalParams.getNameValuePairs(), "LoadData"); // $NON-NLS-1$
        }
        applet.reportStatus(
            name + Messages.getString(BUNDLE_NAME, "RootFolder.18") + nodeName); // $NON-NLS-1$
      } else {
        LOG.info(
            name
                + Messages.getString(BUNDLE_NAME, "RootFolder.19")
                + nodeInfo.getClass().getName()); // $NON-NLS-1$
      }

      if (LOG.isDebugEnabled()) {
        LOG.debug(
            name
                + Messages.getString(BUNDLE_NAME, "RootFolder.20")
                + nodeInfo.toString()); // $NON-NLS-1$
      }
    } finally {
      setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }

    // update the UI so the selected Folder appears in the main panel
    mainPanel.removeAll();
    mainPanel.add((JComponent) nodeInfo, BorderLayout.CENTER);

    mainPanel.validate();
    mainPanel.repaint();
  }