Exemplo n.º 1
0
  /**
   * Get the image group from the gui.
   *
   * @return The iamge group.
   */
  protected String getGroup() {
    Object selected = groupSelector.getSelectedItem();
    if (selected == null) {
      return null;
    }
    if (selected instanceof AddeServer.Group) {
      AddeServer.Group group = (AddeServer.Group) selected;
      return group.getName();
    }

    String groupName = selected.toString().trim();
    if ((groupName.length() > 0)) {
      // Force the get in case they typed a server name
      getServer();
      AddeServer server = getAddeServer();
      if (server != null) {
        AddeServer.Group group =
            getIdv().getIdvChooserManager().addAddeServerGroup(server, groupName, getGroupType());
        if (!group.getActive()) {
          getIdv().getIdvChooserManager().activateAddeServerGroup(server, group);
        }
        // Now put the list of groups back in to the selector
        setGroups();
        groupSelector.setSelectedItem(group);
      }
    }

    return groupName;
  }
Exemplo n.º 2
0
  /**
   * return the String id of the chosen server name
   *
   * @return the server name
   */
  public String getServer() {
    Object selected = serverSelector.getSelectedItem();
    if (selected == null) {
      return null;
    }
    AddeServer server;
    if (selected instanceof AddeServer) {
      server = (AddeServer) selected;
      return server.getName();
    }
    String serverName = selected.toString();
    server = getIdv().getIdvChooserManager().addAddeServer(serverName);
    addeServers = getIdv().getIdvChooserManager().getAddeServers(getGroupType());

    Object selectedGroup = groupSelector.getSelectedItem();
    AddeServer.Group group = null;
    if (selectedGroup != null) {
      group =
          getIdv()
              .getIdvChooserManager()
              .addAddeServerGroup(server, selectedGroup.toString(), getGroupType());
    }

    boolean old = ignoreStateChangedEvents;
    ignoreStateChangedEvents = true;
    GuiUtils.setListData(serverSelector, addeServers);
    serverSelector.setSelectedItem(server);
    setGroups();
    if (group != null) {
      groupSelector.setSelectedItem(group);
    }
    ignoreStateChangedEvents = old;
    return server.getName();
  }
Exemplo n.º 3
0
  /** Set the group list */
  protected void setGroups() {
    AddeServer server = getAddeServer();
    if (server != null) {
      Object selected = groupSelector.getSelectedItem();
      List groups = server.getGroupsWithType(getGroupType());
      GuiUtils.setListData(groupSelector, groups);
      if ((selected != null) && groups.contains(selected)) {
        groupSelector.setSelectedItem(selected);
      }

    } else {
      GuiUtils.setListData(groupSelector, new Vector());
    }
  }
Exemplo n.º 4
0
 /**
  * Get the selected AddeServer
  *
  * @return the server or null
  */
 private AddeServer getAddeServer() {
   Object selected = serverSelector.getSelectedItem();
   if ((selected != null) && (selected instanceof AddeServer)) {
     return (AddeServer) selected;
   }
   return null;
 }
Exemplo n.º 5
0
 /** Reload the list of servers if they have changed */
 public void updateServerList() {
   boolean old = ignoreStateChangedEvents;
   ignoreStateChangedEvents = true;
   List newList = getIdv().getIdvChooserManager().getAddeServers(getGroupType());
   if (Misc.equals(newList, this.addeServers)) {
     ignoreStateChangedEvents = old;
     return;
   }
   this.addeServers = getIdv().getIdvChooserManager().getAddeServers(getGroupType());
   Object selected = serverSelector.getSelectedItem();
   GuiUtils.setListData(serverSelector, addeServers);
   if ((selected != null) && addeServers.contains(selected)) {
     serverSelector.setSelectedItem(selected);
   }
   setGroups();
   ignoreStateChangedEvents = old;
 }
Exemplo n.º 6
0
 /**
  * Add a listener to the given combobox that will set the state to unconnected
  *
  * @param box The box to listen to.
  */
 protected void clearOnChange(final JComboBox box) {
   box.addItemListener(
       new ItemListener() {
         public void itemStateChanged(ItemEvent e) {
           if (!ignoreStateChangedEvents) {
             setState(STATE_UNCONNECTED);
           }
         }
       });
 }
Exemplo n.º 7
0
 /** Load any saved server state */
 private void loadServerState() {
   if (addeServers == null) {
     return;
   }
   String id = getId();
   String[] serverState = (String[]) getIdv().getStore().get(PREF_SERVERSTATE + "." + id);
   if (serverState == null) {
     return;
   }
   AddeServer server = AddeServer.findServer(addeServers, serverState[0]);
   if (server == null) {
     return;
   }
   serverSelector.setSelectedItem(server);
   setGroups();
   if (serverState[1] != null) {
     AddeServer.Group group = (AddeServer.Group) server.findGroup(serverState[1]);
     if (group != null) {
       groupSelector.setSelectedItem(group);
     }
   }
 }
Exemplo n.º 8
0
  /**
   * Create an AddeChooser associated with an IdvChooser
   *
   * @param mgr The chooser manager
   * @param root The chooser.xml node
   */
  public AddeChooser(IdvChooserManager mgr, Element root) {

    super(mgr, root);
    simpleMode = !getProperty(IdvChooser.ATTR_SHOWDETAILS, true);
    this.addeServers = getIdv().getIdvChooserManager().getAddeServers(getGroupType());

    serverSelector =
        new JComboBox(new Vector(addeServers)) {
          public void paint(Graphics g) {
            if (myServerTimeStamp != serverTimeStamp) {
              myServerTimeStamp = serverTimeStamp;
              Misc.runInABit(10, AddeChooser.this, "updateServerList", null);
            }
            super.paint(g);
          }
        };
    serverSelector.setEditable(true);
    serverSelector.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (!ignoreStateChangedEvents) {
              setGroups();
            }
          }
        });

    serverSelector
        .getEditor()
        .getEditorComponent()
        .addMouseListener(
            new MouseAdapter() {
              public void mouseReleased(MouseEvent e) {
                if (!SwingUtilities.isRightMouseButton(e)) {
                  return;
                }
                AddeServer server = getAddeServer();
                if (server == null) {
                  return;
                }
                List items = new ArrayList();
                if (MARK_AS_INACTIVE || server.getIsLocal()) {
                  items.add(
                      GuiUtils.makeMenuItem(
                          "Remove local server: " + server.getName(),
                          AddeChooser.this,
                          "removeServer",
                          server));
                } else {
                  items.add(new JMenuItem("Not a local server"));
                }
                JPopupMenu popup = GuiUtils.makePopupMenu(items);
                popup.show(serverSelector, e.getX(), e.getY());
              }
            });

    groupSelector = new JComboBox();
    groupSelector.setToolTipText("Right click to remove group");
    groupSelector.setEditable(true);
    groupSelector
        .getEditor()
        .getEditorComponent()
        .addMouseListener(
            new MouseAdapter() {
              public void mouseReleased(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                  Object selected = groupSelector.getSelectedItem();
                  if ((selected == null) || !(selected instanceof AddeServer.Group)) {
                    return;
                  }
                  AddeServer.Group group = (AddeServer.Group) selected;
                  List items = new ArrayList();
                  if (MARK_AS_INACTIVE || group.getIsLocal()) {
                    items.add(
                        GuiUtils.makeMenuItem(
                            "Remove local group: " + group.getName(),
                            AddeChooser.this,
                            "removeGroup",
                            group));
                  }

                  final AddeServer server = getAddeServer();

                  if (server != null) {
                    List groups = server.getGroupsWithType(getGroupType(), false);
                    for (int i = 0; i < groups.size(); i++) {
                      final AddeServer.Group inactiveGroup = (AddeServer.Group) groups.get(i);
                      if (inactiveGroup.getActive()) {
                        continue;
                      }
                      JMenuItem mi = new JMenuItem("Re-activate group: " + inactiveGroup);
                      items.add(mi);
                      mi.addActionListener(
                          new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {
                              getIdv()
                                  .getIdvChooserManager()
                                  .activateAddeServerGroup(server, inactiveGroup);
                              setGroups();
                              groupSelector.setSelectedItem(inactiveGroup);
                            }
                          });
                    }
                  }

                  if (items.size() == 0) {
                    items.add(new JMenuItem("Not a local group"));
                  }

                  JPopupMenu popup = GuiUtils.makePopupMenu(items);
                  popup.show(groupSelector, e.getX(), e.getY());
                }
              }
            });
    loadServerState();
    setGroups();
  }