Ejemplo n.º 1
1
  /**
   * Sets a mnemomic for the specified button.
   *
   * @param b button
   * @param mnem mnemonics that have already been assigned
   */
  public static void setMnemonic(final AbstractButton b, final StringBuilder mnem) {
    // do not set mnemonics for Mac! Alt+key used for special characters.
    if (Prop.MAC) return;

    // find and assign unused mnemomic
    final String label = b.getText();
    final int ll = label.length();
    for (int l = 0; l < ll; l++) {
      final char ch = Character.toLowerCase(label.charAt(l));
      if (!letter(ch) || mnem.indexOf(Character.toString(ch)) != -1) continue;
      b.setMnemonic(ch);
      mnem.append(ch);
      break;
    }
  }
 public void setShdPopupOnBtnClick(boolean shdPopup) {
   this.shdPopup = shdPopup;
   if (shdPopup) {
     main.addActionListener(pl);
   } else {
     main.removeActionListener(pl);
   }
 }
 @Override
 public JComponent getPreferredFocusedComponent() {
   final Enumeration<AbstractButton> enumeration = myGroup.getElements();
   while (enumeration.hasMoreElements()) {
     final AbstractButton button = enumeration.nextElement();
     if (button.isSelected()) {
       return button;
     }
   }
   return myPanel;
 }
Ejemplo n.º 4
0
  public void addActions(JPanel buttPanel) {

    AbstractAction netcdfAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            String location = ds.getLocation();
            if (location == null) location = "test";
            int pos = location.lastIndexOf(".");
            if (pos > 0) location = location.substring(0, pos);

            String filename = fileChooser.chooseFilenameToSave(location + ".nc");
            if (filename == null) return;
            writeNetCDF(filename);
          }
        };
    BAMutil.setActionProperties(netcdfAction, "netcdf", "Write netCDF-3 file", false, 'S', -1);
    BAMutil.addActionToContainer(buttPanel, netcdfAction);

    AbstractAction ncstreamAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            String location = ds.getLocation();
            if (location == null) location = "test";
            int pos = location.lastIndexOf(".");
            if (pos > 0) location = location.substring(0, pos);

            String filename = fileChooser.chooseFilenameToSave(location + ".ncs");
            if (filename == null) return;
            writeNcstream(filename);
          }
        };
    BAMutil.setActionProperties(ncstreamAction, "netcdf", "Write ncstream file", false, 'S', -1);
    BAMutil.addActionToContainer(buttPanel, ncstreamAction);

    AbstractButton compareButton = BAMutil.makeButtcon("Select", "Compare to another file", false);
    compareButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            compareDataset();
          }
        });
    buttPanel.add(compareButton);

    AbstractAction attAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            showAtts();
          }
        };
    BAMutil.setActionProperties(attAction, "FontDecr", "global attributes", false, 'A', -1);
    BAMutil.addActionToContainer(buttPanel, attAction);
  }
Ejemplo n.º 5
0
  /**
   * Update helper method. Gets the coordinates of the selected button.
   *
   * @param evt User mouse event.
   * @return int[] of two integers, y and x, or row and col.
   */
  private int[] getButtonCoordinates(MouseEvent evt) {
    AbstractButton abstractButton = (AbstractButton) evt.getSource();

    int y;
    int x = 0;
    outerloop:
    for (y = 0; y < ButtonGrid.length; y++) {
      for (x = 0; x < ButtonGrid[1].length; x++) {
        if (abstractButton.equals(ButtonGrid[y][x])) {
          break outerloop;
          // coordinates saved
        }
      }
    }

    int[] coordinates = {y, x};
    return coordinates;
  }
Ejemplo n.º 6
0
  /**
   * Handles the <tt>ActionEvent</tt>, when one of the tool bar buttons is clicked.
   *
   * @param e the <tt>ActionEvent</tt> that notified us
   */
  public void actionPerformed(ActionEvent e) {
    AbstractButton button = (AbstractButton) e.getSource();
    String buttonText = button.getName();

    ChatPanel chatPanel = chatContainer.getCurrentChat();

    if (buttonText.equals("previous")) {
      chatPanel.loadPreviousPageFromHistory();
    } else if (buttonText.equals("next")) {
      chatPanel.loadNextPageFromHistory();
    } else if (buttonText.equals("sendFile")) {
      SipCommFileChooser scfc =
          GenericFileDialog.create(
              null,
              "Send file...",
              SipCommFileChooser.LOAD_FILE_OPERATION,
              ConfigurationUtils.getSendFileLastDir());
      File selectedFile = scfc.getFileFromDialog();
      if (selectedFile != null) {
        ConfigurationUtils.setSendFileLastDir(selectedFile.getParent());
        chatContainer.getCurrentChat().sendFile(selectedFile);
      }
    } else if (buttonText.equals("invite")) {
      ChatInviteDialog inviteDialog = new ChatInviteDialog(chatPanel);

      inviteDialog.setVisible(true);
    } else if (buttonText.equals("leave")) {
      ChatRoomWrapper chatRoomWrapper =
          (ChatRoomWrapper) chatPanel.getChatSession().getDescriptor();
      ChatRoomWrapper leavedRoomWrapped =
          GuiActivator.getMUCService().leaveChatRoom(chatRoomWrapper);
    } else if (buttonText.equals("call")) {
      call(false, false);
    } else if (buttonText.equals("callVideo")) {
      call(true, false);
    } else if (buttonText.equals("desktop")) {
      call(true, true);
    } else if (buttonText.equals("options")) {
      GuiActivator.getUIService().getConfigurationContainer().setVisible(true);
    } else if (buttonText.equals("font")) chatPanel.showFontChooserDialog();
    else if (buttonText.equals("createConference")) {
      chatPanel.showChatConferenceDialog();
    }
  }
  public void layoutComponents() {
    setLayout(new BorderLayout());
    add(main, BorderLayout.CENTER);

    if (popperIsVisible) {
      if (getPopperButtonLocation() == RIGHT) {
        popper.setPreferredSize(new Dimension(14, main.getHeight()));
        add(popper, BorderLayout.EAST);
      } else if (getPopperButtonLocation() == BOTTOM) {
        popper.setPreferredSize(new Dimension(main.getWidth(), 14));
        add(popper, BorderLayout.SOUTH);

        setPopperArrowDirection(DOWN);
        setPopupLocation(popper.getX(), popper.getY() + popper.getHeight() + 5);
      }
    }

    Utilities.updateView(this);
  }
  public void setUseFlatUI(boolean b) {
    main.setContentAreaFilled(!b);
    main.setFocusPainted(!b);
    main.setBorderPainted(!b);
    main.setMargin(new Insets(1, 1, 1, 1));

    popper.setContentAreaFilled(!b);
    popper.setFocusPainted(!b);
    popper.setBorderPainted(!b);
    popper.setMargin(new Insets(1, 1, 1, 1));

    setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    setOpaque(false);

    MouseAdapter ma =
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            main.setContentAreaFilled(true);
            main.setBackground(new Color(216, 240, 254));
            // m.getMainButton().setForeground( Color.black );
            setBorder(new LineBorder(new Color(200, 200, 200), 1));
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

            popper.setBackground(new Color(242, 242, 242));
            popper.setContentAreaFilled(true);
            popper.setBorder(menu.getBorder());
          }

          public void mouseExited(MouseEvent e) {
            main.setContentAreaFilled(false);
            //	c.setForeground( Color.black );
            setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
            setCursor(Cursor.getDefaultCursor());

            popper.setContentAreaFilled(false);
            popper.setBorder(null);
          }
        };

    main.addMouseListener(ma);
    popper.addMouseListener(ma);
  }
  private static boolean hasMnemonic(final Container container, final int keyCode) {
    if (container == null) return false;

    final Component[] components = container.getComponents();
    for (Component component : components) {
      if (component instanceof AbstractButton) {
        final AbstractButton button = (AbstractButton) component;
        if (button instanceof JBOptionButton) {
          if (((JBOptionButton) button).isOkToProcessDefaultMnemonics()) return true;
        } else {
          if (button.getMnemonic() == keyCode) return true;
        }
      }
      if (component instanceof JLabel) {
        final JLabel label = (JLabel) component;
        if (label.getDisplayedMnemonic() == keyCode) return true;
      }
      if (component instanceof Container) {
        if (hasMnemonic((Container) component, keyCode)) return true;
      }
    }
    return false;
  }
Ejemplo n.º 10
0
  public void createButtons(String text, Icon icon) {
    if (main == null) {
      main = new JButton(text, icon);

      if (text == null) {
        main.setMargin(new Insets(0, 0, 0, 0));
      }
    }

    // main.setFont( new Font("Verdana", Font.PLAIN, 11) );
    ImageIcon img = new ImageIcon("resources/images/popicon.gif");
    popper =
        new JButton(/*img*/ ) {

          public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2 = (Graphics2D) g;
            int width = getWidth(), height = getHeight();
            int midWidth = width / 2, midHeight = height / 2;

            int[] xpoints = {midWidth - 4, midWidth, midWidth + 4};
            int[] ypoints = {midHeight - 1, midHeight + 3, midHeight - 1};

            if (ARROW_DIRECTION == FORWARD) {
              xpoints = new int[] {midWidth - 3, midWidth - 3, midWidth + 2};
              ypoints = new int[] {midHeight - 4, midHeight + 4, midHeight};
            }

            g2.setColor(getPopperArrowColor());
            g2.fill(new Polygon(xpoints, ypoints, 3));
          }
        };

    // popper.setPreferredSize( new Dimension(img.getImage().getWidth(this) + 10,

    popper.addActionListener(this);

    setBorder(null);
    // setLayout( new BoxLayout(this, BoxLayout.X_AXIS) );
    layoutComponents();
  }
Ejemplo n.º 11
0
  public void showMenu() {
    if (LOCATION == BELOW) {
      setPopupLocation(main.getX() - main.getWidth(), main.getY() + getHeight());
    } else if (LOCATION == ABOVE) {
      setPopupLocation(main.getX() - main.getWidth(), main.getY() - menu.getHeight());
    }

    if (getPopperButtonLocation() == RIGHT) {
      if (getPopperButtonLocation() == RIGHT) {
        tempPopArrowDir = getPopperArrowDirection();
      }

      setPopperArrowDirection(DOWN);
    }

    menu.show(popper, getPopupX(), getPopupY());
  }
Ejemplo n.º 12
0
 public void addActionListener(ActionListener l) {
   main.addActionListener(l);
   listener = l;
 }
Ejemplo n.º 13
0
 public void setEnabled(boolean b) {
   main.setEnabled(b);
   popper.setEnabled(b);
 }
Ejemplo n.º 14
0
  /**
   * Handles the <tt>ActionEvent</tt>, when one of the tool bar buttons is clicked.
   *
   * @param e the <tt>ActionEvent</tt> that notified us
   */
  public void actionPerformed(ActionEvent e) {
    AbstractButton button = (AbstractButton) e.getSource();
    String buttonText = button.getName();

    ChatPanel chatPanel = chatContainer.getCurrentChat();

    if (buttonText.equals("previous")) {
      chatPanel.loadPreviousPageFromHistory();
    } else if (buttonText.equals("next")) {
      chatPanel.loadNextPageFromHistory();
    } else if (buttonText.equals("sendFile")) {
      SipCommFileChooser scfc =
          GenericFileDialog.create(
              null,
              "Send file...",
              SipCommFileChooser.LOAD_FILE_OPERATION,
              ConfigurationUtils.getSendFileLastDir());
      File selectedFile = scfc.getFileFromDialog();
      if (selectedFile != null) {
        ConfigurationUtils.setSendFileLastDir(selectedFile.getParent());
        chatContainer.getCurrentChat().sendFile(selectedFile);
      }
    } else if (buttonText.equals("history")) {
      HistoryWindow history;

      HistoryWindowManager historyWindowManager =
          GuiActivator.getUIService().getHistoryWindowManager();

      ChatSession chatSession = chatPanel.getChatSession();

      if (historyWindowManager.containsHistoryWindowForContact(chatSession.getDescriptor())) {
        history = historyWindowManager.getHistoryWindowForContact(chatSession.getDescriptor());

        if (history.getState() == JFrame.ICONIFIED) history.setState(JFrame.NORMAL);

        history.toFront();
      } else {
        history = new HistoryWindow(chatPanel.getChatSession().getDescriptor());

        history.setVisible(true);

        historyWindowManager.addHistoryWindowForContact(chatSession.getDescriptor(), history);
      }
    } else if (buttonText.equals("invite")) {
      ChatInviteDialog inviteDialog = new ChatInviteDialog(chatPanel);

      inviteDialog.setVisible(true);
    } else if (buttonText.equals("leave")) {
      ConferenceChatManager conferenceManager =
          GuiActivator.getUIService().getConferenceChatManager();
      conferenceManager.leaveChatRoom((ChatRoomWrapper) chatPanel.getChatSession().getDescriptor());
    } else if (buttonText.equals("call")) {
      call(false, false);
    } else if (buttonText.equals("callVideo")) {
      call(true, false);
    } else if (buttonText.equals("desktop")) {
      call(true, true);
    } else if (buttonText.equals("options")) {
      GuiActivator.getUIService().getConfigurationContainer().setVisible(true);
    } else if (buttonText.equals("font")) chatPanel.showFontChooserDialog();
  }
Ejemplo n.º 15
0
 @Override
 public void refresh(final GUI main, final AbstractButton button) {
   button.setEnabled(!undo.last());
 }
Ejemplo n.º 16
0
 @Override
 public void refresh(final GUI main, final AbstractButton button) {
   button.setEnabled(text.marked());
 }
Ejemplo n.º 17
0
 @Override
 public void refresh(final GUI main, final AbstractButton button) {
   button.setEnabled(clip() != null);
 }