Пример #1
0
  public ConnectionForm() {
    setContentPane(contentPane);
    setModal(true);
    getRootPane().setDefaultButton(buttonOK);

    JMenuBar menuBar = new JMenuBar();
    menuBar.setVisible(true);

    JMenu menu = new JMenu("Menu");
    menu.setVisible(true);

    JMenuItem statementItem = new JMenuItem("SQL Insert");
    statementItem.setVisible(true);
    statementItem.addActionListener(new SQLImportActionListener());
    statementItem.setEnabled(false);

    JMenuItem importItem = new JMenuItem("Files Import");
    importItem.setEnabled(false);
    importItem.setVisible(true);

    menu.add(statementItem);
    menu.add(importItem);
    menuBar.add(menu);
    setJMenuBar(menuBar);

    buttonOK.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
            int result = fileChooser.showOpenDialog(getParent());
          }
        });

    dbField.addMouseListener(new DBFileMouseListener(getParent()));
    filesField.addMouseListener(new SQLFilesMouseListener(getParent()));

    // call onCancel() when cross is clicked
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            onCancel();
          }
        });

    // call onCancel() on ESCAPE
    contentPane.registerKeyboardAction(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            onCancel();
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
  }
Пример #2
0
    public void show(Component invoker, int x, int y) {
      ViperViewMediator mediator = getMediator();
      Point pnt = new Point(x, y);
      EnhancedTable tab = getTable();
      int row = tab.rowAtPoint(pnt);
      desc = getCurrentModel().getDescriptorAtRow(row);
      int col = tab.columnAtPoint(pnt);
      Object cellValue = tab.getValueAt(row, col);
      if (cellValue instanceof Attribute) {
        attr = (Attribute) cellValue;

        // hide the "Occlusions..." option when we're not dealing with a Textline object
        boolean isTextline = attr.getAttrConfig().getAttrType().endsWith("textline");
        occlusions.setVisible(isTextline);
        occSeparator.setVisible(isTextline);

        Instant now = mediator.getCurrentFrame();
        if (now == null) {
          mediator.getDisplayWRTManager().setAttribute(null, null);
          wrt.setEnabled(false);
          wrt.setSelected(false);
        } else {
          boolean isDwrt = attr == mediator.getDisplayWRTManager().getAttribute();
          boolean dwrtable =
              (attr.getAttrValueAtInstant(now) instanceof HasCentroid
                  && attr.getDescriptor().getValidRange().contains(now));
          wrt.setEnabled(dwrtable);
          wrt.setSelected(isDwrt);
        }
      } else {
        attr = null;
        wrt.setEnabled(false);
        wrt.setSelected(false);
      }
      if (null != desc) {
        PropagateInterpolateModule proper = getMediator().getPropagator();
        p.setSelected(proper.isPropagatingThis(desc));
        v.setSelected(mediator.isThisValidNow(desc));
        resetMarks();
        super.show(invoker, x, y);
      }
    }
  private void showPopup() {
    if (isEnabled()) {
      if (popup.isVisible()) {
        popup.setVisible(false);
      } else {
        Component[] components = popup.getComponents();
        if (components != null) {
          for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof Item) ((Item) components[i]).removeActionListener(this);
            else if (components[i] instanceof MenuItem) {
              Component[] subcomponents = ((MenuItem) components[i]).getComponents();
              for (int j = 0; j < components.length; j++) {
                if (components[j] instanceof Item)
                  ((Item) components[j]).removeActionListener(this);
              }
            }
          }
        }
        popup.removeAll();
        if (values == null) return;
        for (int i = 0; i < values.length; i++) {
          JMenuItem item = null;
          if (values[i] instanceof ListDescriptor) {
            ListDescriptor descriptor = (ListDescriptor) values[i];
            Icon icon = descriptor.getIcon();
            item = new Item(values[i].toString(), icon, i);
            item.addActionListener(this);
          } else if (values[i] instanceof AddElement) {
            AddElement element = (AddElement) values[i];
            Icon icon = element.getIcon();

            Object[] choiceValues = element.getChoiceValues();
            if (choiceValues != null) {
              item = new MenuItem(element.toString(), icon, i);
              for (int j = 0; j < choiceValues.length; j++) {
                if (choiceValues[j] == null) {
                  ((JMenu) item).addSeparator();
                  continue;
                }
                Item subItem = new Item(choiceValues[j].toString(), j);
                ((JMenu) item).add(subItem);
                subItem.setParentIndex(i);
                subItem.addActionListener(this);
              }
            } else {
              item = new Item(element.toString(), icon, i);
              item.addActionListener(this);
            }
            item.setVisible(element.isVisible());
            item.setEnabled(element.isEnabled());
          } else {
            if (values[i] != null) {
              item = new Item(values[i].toString(), i);
              item.addActionListener(this);
            }
          }
          if (item != null) {
            popup.add(item);
          } else popup.addSeparator();
        }
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                AwtUtil.showPopupPanel(PopupMenuButton.this, popup);
              }
            });
      }
    }
  }