Пример #1
0
  /** When a new set of saved statements come in, refresh the menu of saved statements. */
  private void refreshSaveMenu() {
    ArrayList list;
    // first, delete what's already there
    for (; ; ) {
      Component comp = popup.getComponent(1);
      if (!(comp instanceof JMenuItem)) break;

      JMenuItem item = (JMenuItem) comp;
      if (item.getActionCommand().startsWith("save:")) popup.remove(1);
      else break;
    }
    StatementHistory history;
    history = sshare.statementHistory();
    // now insert the new list of saved statements
    list = history.getNamedStatementList();
    Color bgColor = Util.getBgColor();
    for (int i = 0; i < list.size(); i++) {
      ArrayList nameNlabel = (ArrayList) list.get(i);
      JMenuItem item = new JMenuItem("  " + (String) nameNlabel.get(1));
      item.setActionCommand("save:" + (String) nameNlabel.get(0));
      popup.add(item, 1);
      //	    item.setBackground(bgColor);
      item.addActionListener(popActionListener);
    }
  } // refreshSaveMenu()
Пример #2
0
 /**
  * constructor
  *
  * @param values list of values, ArrayList
  */
 public MPopButton(ArrayList values) {
   this();
   for (int i = 0; i < values.size(); i++) {
     JMenuItem item = popup.add((String) values.get(i));
     item.addActionListener(popActionListener);
     popup.add(item);
   }
   m_aListValues = values;
   setDefaultText();
 } // MPopButton()
Пример #3
0
 /**
  * constructor
  *
  * @param values list of values, String[]
  */
 public MPopButton(String[] values) {
   this();
   for (int i = 0; i < values.length; i++) {
     JMenuItem item = popup.add(values[i]);
     item.addActionListener(popActionListener);
     popup.add(item);
     m_aListValues.add(values[i]);
   }
   setDefaultText();
 } // MPopButton()
Пример #4
0
    public void mouseClicked(MouseEvent evt) {
      int btn = evt.getButton();
      if (btn == MouseEvent.BUTTON3) {
        JPopupMenu helpMenu = new JPopupMenu();
        String helpLabel = Util.getLabel("CSHMenu");
        JMenuItem helpMenuItem = new JMenuItem(helpLabel);
        helpMenuItem.setActionCommand("help");
        helpMenu.add(helpMenuItem);

        ActionListener alMenuItem =
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                String topic = "";
                try {
                  JComponent c1 = (JComponent) tabbedPane.getSelectedComponent();
                  // This component should contain the following embedded items.
                  // We want m_helplink out of the top VGroup.
                  //   PushpinObj
                  //     XMLToolPanel
                  //       JScrollpane
                  //         JViewport
                  //           JPanel
                  //             VGroup
                  // Work down to the VGroup, checking for class type along
                  // the way.
                  if (c1 instanceof PushpinObj) {
                    Component c2[] = c1.getComponents();
                    int cnt;
                    for (cnt = 0; cnt < c2.length; cnt++) {
                      // The PushpinObj can have multiple items, find the one we want
                      if (c2[cnt] instanceof XMLToolPanel) break;
                    }
                    if (cnt < c2.length && c2[cnt] instanceof XMLToolPanel) {
                      Component c3[] = ((JComponent) c2[cnt]).getComponents();
                      if (c3[0] instanceof JScrollPane) {
                        Component c4[] = ((JComponent) c3[0]).getComponents();
                        if (c4[0] instanceof JViewport) {
                          Component c5[] = ((JComponent) c4[0]).getComponents();
                          if (c5[0] instanceof JPanel) {
                            Component c6[] = ((JComponent) c5[0]).getComponents();
                            if (c6[0] instanceof VGroup) {
                              // Get the helplink info from the VGroup
                              topic = ((VGroup) c6[0]).getAttribute(VObjDef.HELPLINK);
                            }
                          }
                        }
                      }
                    }
                  }
                  // If no helplink found, try the Tab's name
                  if (topic == null || topic.length() == 0) {
                    topic = c1.getName();
                    if (topic.equals("Locator")) topic = getLocatorName();
                    topic = topic.replace(" ", "_");
                  }
                } catch (Exception ex) {
                }
                // Get the ID and display the help content
                CSH_Util.displayCSHelp(topic);
              }
            };
        helpMenuItem.addActionListener(alMenuItem);

        Point pt = evt.getPoint();
        helpMenu.show(VTabbedToolPanel.this, (int) pt.getX(), (int) pt.getY());
      }
    }
Пример #5
0
 /**
  * set text to the specified item index
  *
  * @param index index
  */
 public void setText(int index) {
   JMenuItem item = (JMenuItem) popup.getComponent(index);
   setText(item.getText());
 } // setText()
Пример #6
0
 public void setEnabled(int index, boolean bEnabled) {
   JMenuItem item = (JMenuItem) popup.getComponent(index);
   if (item != null) item.setEnabled(bEnabled);
 }
Пример #7
0
 /** set default text */
 public void setDefaultText() {
   JMenuItem item = (JMenuItem) popup.getComponent(0);
   if (item != null) setText(item.getText());
 } // setDefaultText()
Пример #8
0
  public void fillPopupMenu() {
    JMenuItem item;
    TextImageIcon textIcon;
    StatementHistory history;
    int rowCount = 0;
    int numRows = 0;
    Insets margin = new Insets(0, 0, 0, 0);

    // Get the font defined in the displayOptions panel for menus
    Font ft = DisplayOptions.getFont("Menu1");
    // We need a fairly small font, so make it 2 smaller.
    int size = ft.getSize();
    // If larger than 12, subtract 2
    if (size > 12) size -= 2;
    Font font = DisplayOptions.getFont(ft.getName(), ft.getStyle(), size);

    // This flag is used so that we only fill the menu when needed
    if (menuAlreadyFilled) return;

    menuAlreadyFilled = true;

    history = sshare.statementHistory();

    ArrayList list = history.getNamedStatementList();
    Color bgColor = Util.getBgColor();
    // Only show the Saved Statements section if there are some.
    if (list != null && list.size() != 0) {
      item = popup.add("Saved Statements");
      rowCount++;
      //	    item.setForeground(Color.blue);
      //	    item.setBackground(bgColor);
      item.setFont(font);
      item.setMargin(margin);
      popup.add(item);

      for (int i = 0; i < list.size(); i++) {
        ArrayList nameNlabel = (ArrayList) list.get(i);
        // first item in nameNlabel is name and second is label
        item = popup.add("  " + (String) nameNlabel.get(1));
        rowCount++;
        item.setActionCommand("save:" + (String) nameNlabel.get(0));
        //		item.setBackground(bgColor);
        item.addActionListener(popActionListener);
        item.setFont(font);
        item.setMargin(margin);
      }
    }
    // the rest of menu (return object types, statement types, etc.)
    ShufflerService shufflerService = sshare.shufflerService();
    ArrayList objTypes = shufflerService.getAllMenuObjectTypes();

    for (int i = 0; i < objTypes.size(); i++) {
      String objType = (String) objTypes.get(i);

      // Do not display menu for DB_AVAIL_SUB_TYPES
      if (objType.equals(Shuf.DB_AVAIL_SUB_TYPES)) continue;

      // addSeparator looks bad using GridLayout because it creates rows
      // and columns which are all equal in size.  It cannot have a row
      // with a separator which is a different height than the other
      // rectangles it creates. So just use dashes.
      item = popup.add(separator);
      item.setFont(font);
      item.setMargin(margin);
      rowCount++;
      item = popup.add(shufflerService.getCategoryLabel(objType));
      rowCount++;
      //	    item.setForeground(Color.blue);
      item.setActionCommand("title:" + objType);
      //	    item.setBackground(bgColor);
      item.addActionListener(popActionListener);
      item.setFont(font);
      item.setMargin(margin);

      ArrayList menuStrings = shufflerService.getmenuStringsThisObj(objType);

      // If current rowCount plus the next section size is too big,
      // specify the numRows to the current value of rowCount -1.
      // That is, put this next section in a new column.
      // 47 is emperical number of rows to fit 90% full screen.
      if (numRows == 0 && rowCount - 1 + menuStrings.size() > 44) {

        numRows = rowCount - 2;
      }

      for (int j = 0; j < menuStrings.size(); j++) {
        String menuString = (String) menuStrings.get(j);
        item = popup.add("  " + menuString);
        rowCount++;
        item.setActionCommand("command:" + objType + "/" + menuString);
        //		item.setBackground(bgColor);
        item.addActionListener(popActionListener);
        item.setFont(font);
        item.setMargin(margin);
      }
      // The spotter menu changes dynamically when
      // the list of saved statements changes.
      history.addStatementListener(
          new StatementAdapter() {
            public void saveListChanged() {
              refreshSaveMenu();
            }
          });
    }

    if (numRows == 0) numRows = rowCount;

    GridLayoutCol lm = new GridLayoutCol(numRows, 0);
    popup.setLayout(lm);
  }