Example #1
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();
  }
Example #2
0
  private void populatePortTable(List ports) {

    logger.debug("Filling port table");
    // get an array of ports
    final PortInfoController[] portcontrollers =
        (PortInfoController[]) ports.toArray(new PortInfoController[ports.size()]);

    // setup the panel
    boxControllers.removeAll();

    // add the ports to the data array
    for (int index = 0; index < portcontrollers.length; index++) {

      final int indexFinal = index;
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {

              boxControllers.add(portcontrollers[indexFinal].getView());
            }
          });
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {

            boxControllers.add(Box.createVerticalGlue());
          }
        });
  }
Example #3
0
  public void setEntity(java.lang.Object ent) {
    Method[] methods = ent.getClass().getDeclaredMethods();
    box.removeAll();
    for (Method m : methods) {
      if (m.getName().toLowerCase().startsWith("get")) {
        String attName = m.getName().substring(3);
        Object result;
        try {
          result = m.invoke(ent, new Object[] {});
          String value = "null";
          if (result != null) value = result.toString();
          JPanel attPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
          attPane.add(new JLabel(attName + " : " + m.getReturnType().getName() + " = " + value));
          box.add(attPane);
        } catch (IllegalArgumentException e) {

          e.printStackTrace();
        } catch (IllegalAccessException e) {

          e.printStackTrace();
        } catch (InvocationTargetException e) {

          e.printStackTrace();
        }
      }
    }
  }
  /** 读取project目录并完成初始化 */
  private void init() {
    contentBox.removeAll(); // clear
    projectPanels.clear(); // clear
    publicLibraries.clear(); // clear

    File projectsDir = new File("projects");
    if (!projectsDir.exists()) projectsDir.mkdir();
    File libraryDir = new File("libProjects");
    if (!libraryDir.exists()) libraryDir.mkdir();

    syncProjectConfig();

    File[] libFiles = libraryDir.listFiles(new ProjectFileFilter());
    File[] projectFiles = projectsDir.listFiles(new ProjectFileFilter());

    List<File> projects = new ArrayList<File>();
    if (projectFiles != null) projects.addAll(Arrays.asList(projectFiles));
    if (libFiles != null) projects.addAll(Arrays.asList(libFiles));

    EditProjectHandler editHandler = new EditProjectHandler();
    for (File projectFile : projects) {
      if (projectFile.getName().equals(".project")) continue; // 加强容错性
      BatchPack pack = new BatchPack(projectFile.getAbsolutePath());
      String fullName = projectFile.getName();
      String fileName = fullName.substring(0, fullName.lastIndexOf('.'));
      if (pack.needImport()) {
        batchButton.setEnabled(false);
        progressBar.setString("正在同步导入" + fileName);
        progressBar.setIndeterminate(true);
        pack.importFromSVN();
        records.setProjectVersion(
            projectFile.getAbsolutePath(), pack.getSVNVersion()); // ensure latest version
        records.saveRecords();
        progressBar.setIndeterminate(false);
        progressBar.setString("");
        batchButton.setEnabled(true);
      }
      ProjectPanel projectPanel = new ProjectPanel(pack, fileName);
      projectPanel.setEditProjectListener(editHandler);
      projectPanel.updateUI();
      projectPanels.add(projectPanel);
      contentBox.add(projectPanel);
    }

    // prepare library
    for (ProjectPanel panel : projectPanels) {
      BatchPack pack = panel.getProjectBatch();
      if (!pack.isLibrary()) continue;
      Attributes attributes = pack.getAttributes();
      String projectPath = attributes.getProperty("projectPath");
      String projectName = new File(projectPath).getName();
      publicLibraries.put(projectName, projectPath);
    }
    // modify project to reference public library
    for (ProjectPanel panel : projectPanels) {
      prepareProjectPanel(panel);
    }
    contentBox.updateUI();
  }
Example #5
0
  protected void refreshCacheTab() {
    // refresh list of cache hosts
    cacheBox.removeAll();
    ArrayList<JLabel> labels = new ArrayList<JLabel>();
    File cache = ResourceLoader.getOSPCache();
    File[] hosts = cache == null ? new File[0] : cache.listFiles(ResourceLoader.OSP_CACHE_FILTER);
    clearCacheButton.setEnabled(hosts.length > 0);

    if (hosts.length == 0) {
      JLabel label = new JLabel(ToolsRes.getString("LibraryManager.Cache.IsEmpty")); // $NON-NLS-1$
      label.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
      Box box = Box.createHorizontalBox();
      box.add(label);
      box.add(Box.createHorizontalGlue());
      cacheBox.add(box);
      return;
    }

    for (File hostFile : hosts) {
      // eliminate the "osp-" that starts all cache host filenames
      String hostText = hostFile.getName().substring(4).replace('_', '.');
      long bytes = getFileSize(hostFile);
      long size = bytes / (1024 * 1024);
      if (bytes > 0) {
        if (size > 0) hostText += " (" + size + " MB)"; // $NON-NLS-1$ //$NON-NLS-2$
        else hostText += " (" + bytes / 1024 + " kB)"; // $NON-NLS-1$ //$NON-NLS-2$
      }
      JLabel label = new JLabel(hostText);
      label.setToolTipText(hostFile.getAbsolutePath());
      labels.add(label);

      ClearHostButton button = new ClearHostButton(hostFile);

      Box bar = Box.createHorizontalBox();
      bar.add(label);
      bar.add(button);
      bar.add(Box.createHorizontalGlue());

      cacheBox.add(bar);
      FontSizer.setFonts(cacheBox, FontSizer.getLevel());
    }

    // set label sizes
    FontRenderContext frc = new FontRenderContext(null, false, false);
    Font font = labels.get(0).getFont();
    int w = 0;
    for (JLabel next : labels) {
      Rectangle2D rect = font.getStringBounds(next.getText(), frc);
      w = Math.max(w, (int) rect.getWidth());
    }
    Dimension labelSize = new Dimension(w + 48, 20);
    for (JLabel next : labels) {
      next.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
      next.setPreferredSize(labelSize);
    }
  }
Example #6
0
  protected void refreshSearchTab() {
    // refresh list of cached search targets
    searchBox.removeAll();
    checkboxes.clear();
    ArrayList<JLabel> labels = new ArrayList<JLabel>();
    for (LibraryResource next : browser.getSearchCacheTargets()) {
      String path = next.collectionPath;
      if (path == null) continue;

      String name = next.toString();
      JLabel label = new JLabel(name);
      label.setToolTipText(path);
      labels.add(label);

      SearchCheckBox checkbox = new SearchCheckBox(path);
      checkboxes.add(checkbox);
      JButton button = new DeleteButton(path);

      Box bar = Box.createHorizontalBox();
      bar.add(label);
      bar.add(checkbox);
      bar.add(button);
      bar.add(Box.createHorizontalGlue());

      searchBox.add(bar);
      FontSizer.setFonts(searchBox, FontSizer.getLevel());
    }
    if (labels.isEmpty()) return;

    // set label sizes
    FontRenderContext frc = new FontRenderContext(null, false, false);
    Font font = labels.get(0).getFont();
    int w = 0;
    for (JLabel next : labels) {
      Rectangle2D rect = font.getStringBounds(next.getText(), frc);
      w = Math.max(w, (int) rect.getWidth());
    }
    Dimension labelSize = new Dimension(w + 48, 20);
    for (JLabel next : labels) {
      next.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
      next.setPreferredSize(labelSize);
    }
  }
Example #7
0
  /* (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();
  }