Beispiel #1
0
  private void initGui() {
    _listScrollPane.getViewport().add(_shoutsList);
    JScrollPane inputScrollPane = new JScrollPane();
    JPanel horizontalLimit =
        new JPanel() {
          @Override
          public Dimension getPreferredSize() {
            Dimension preferredSize = super.getPreferredSize();
            preferredSize.setSize(getWidth() - 30, preferredSize.getHeight());
            return preferredSize;
          }
        };
    horizontalLimit.setLayout(new BorderLayout());
    horizontalLimit.add(_messageInputPane.getComponent());
    inputScrollPane.getViewport().add(horizontalLimit);

    JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, _listScrollPane, inputScrollPane);
    split.setBorder(new EmptyBorder(0, 0, 0, 0));

    split.setOpaque(false);
    split.setDividerLocation((int) (getHeight() * 0.68));
    split.setDividerSize(3);
    setLayout(new BorderLayout());
    add(split, BorderLayout.CENTER);

    _shoutsList.setBorder(new EmptyBorder(0, 0, 0, 0));
    _messageInputPane.getComponent().setBorder(new EmptyBorder(0, 0, 0, 0));

    _shoutsList.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent e) {
            _shoutsList.setEditable(false);
          }

          @Override
          public void focusLost(FocusEvent e) {
            _shoutsList.setEditable(true);
          }
        });
  }
  private void setGridBagLayout() {
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridBagLayout());

    contentPane.add(
        _nicknameLb,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 5),
            0,
            0));

    contentPane.add(
        _nicknameTF.getComponent(),
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 0, 0, 5),
            0,
            0));

    contentPane.add(
        _sealLb,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 5),
            0,
            0));

    contentPane.add(
        _sealScroll,
        new GridBagConstraints(
            0,
            2,
            5,
            1,
            0.5,
            0.5,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    contentPane.add(
        _inetAddressesPanel,
        new GridBagConstraints(
            0,
            3,
            2,
            1,
            1.0,
            0.2,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    contentPane.add(
        _friendsLb,
        new GridBagConstraints(
            0,
            3,
            2,
            1,
            1.0,
            0.2,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    contentPane.add(
        _friendsCb,
        new GridBagConstraints(
            0,
            3,
            2,
            1,
            1.0,
            0.2,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    contentPane.add(
        _acceptFriendBt,
        new GridBagConstraints(
            0,
            3,
            2,
            1,
            1.0,
            0.2,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    _inetAddressesPanel.setLayout(new GridBagLayout());
    _inetAddressesPanel.add(
        _inetAddressesScroll,
        new GridBagConstraints(
            0,
            1,
            12,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    _inetAddressesPanel.add(
        _hostLb,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 5),
            0,
            0));

    _inetAddressesPanel.add(
        _hostTF,
        new GridBagConstraints(
            1,
            2,
            7,
            1,
            2.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    _inetAddressesPanel.add(
        _portLb,
        new GridBagConstraints(
            9,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 5, 5),
            0,
            0));

    _inetAddressesPanel.add(
        _portTF,
        new GridBagConstraints(
            10,
            2,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 5),
            0,
            0));

    _inetAddressesPanel.add(
        _newBt,
        new GridBagConstraints(
            7,
            4,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));

    _inetAddressesPanel.add(
        _saveBt,
        new GridBagConstraints(
            8,
            4,
            3,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));

    _inetAddressesPanel.add(
        _deleteBt,
        new GridBagConstraints(
            11,
            4,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
  }
  private void initGui() {
    setTitle("Contact Info:");
    setResizable(false);

    _nicknameLb = new JLabel("Nickname:");
    _nicknameTF =
        my(ReactiveWidgetFactory.class)
            .newTextField(
                nicknameString(), nicknameSetter(), NotificationPolicy.OnEnterPressedOrLostFocus);

    _sealLb = new JLabel("Seal:");
    _sealTP =
        my(ReactiveWidgetFactory.class)
            .newTextPane(
                contactsFormattedSealString(),
                contactsSealSetter(),
                NotificationPolicy.OnEnterPressedOrLostFocus);
    _sealTP.getMainWidget().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
    _sealScroll =
        new JScrollPane(
            _sealTP.getMainWidget(),
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    _friendsLb = new JLabel("Friends:");
    _friendsCb =
        new JComboBox(new String[] {"Whatsit", "Whatsisname", "Whatsername", "Whatchamacallit"});
    _acceptFriendBt = new JButton("Accept");

    _inetAddressesList =
        my(ReactiveWidgetFactory.class)
            .newList(
                new ContactInternetAddressList().addresses(),
                new LabelProvider<InternetAddress>() {
                  @Override
                  public Signal<Image> imageFor(InternetAddress element) {
                    return my(Signals.class).constant(null);
                  }

                  @Override
                  public Signal<String> textFor(InternetAddress element) {
                    return my(Signals.class)
                        .constant(element.host() + " : " + element.port().currentValue());
                  }
                });

    _inetAddressesPanel = new JPanel();
    _inetAddressesScroll = my(SynthScrolls.class).create();
    _inetAddressesScroll.getViewport().add(addresses());

    _hostLb = new JLabel("Host:");
    _hostTF = new JTextField();

    _portLb = new JLabel("Port:");
    _portTF = new JTextField();

    _newBt = new JButton("New");
    _newBt.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            newInternetAddress();
          }
        });

    _saveBt = new JButton("Save");
    _saveBt.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            saveInternetAddress();
          }
        });

    _deleteBt = new JButton("Delete");
    _deleteBt.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            delInternetAddress();
          }
        });

    setGridBagLayout();
    addListSelectionListestener();

    this.setSize(330, 310);
  }