⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hostwidget.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:
/**
 * The contents of this file are subject to the OAA  Community Research
 * License Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License
 * at http://www.ai.sri.com/~oaa/.  Software distributed under the License
 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * rights and limitations under the License.  Portions of the software are
 * Copyright (c) SRI International, 1999-2003.  All rights reserved.
 * "OAA" is a registered trademark, and "Open Agent Architecture" is a
 * trademark, of SRI International, a California nonprofit public benefit
 * corporation.
*/

package com.sri.oaa2.agt.startit;

import java.util.*;

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

public class HostWidget extends JPanel {
  
  private final static String NONE = "Local";
  private final static String SSH  = "SSH:";
  private final static String RSH  = "rsh:";

  private final static String BLANK = "blank";
  private final static String LOGIN = "login";

  private final JComboBox select;

  private final JPanel rhPanel;
  private final CardLayout layout;
  private final JPanel blank;
  private final JPanel userAtHost;

  private final JTextField username;
  private final OptionWidget.TextMenuWidget hostname;

  public HostWidget() {
    Vector v = new Vector();
    setLayout(new FlowLayout(FlowLayout.RIGHT,2,2));

    rhPanel = new JPanel();
    layout = new CardLayout();
    rhPanel.setLayout(layout);

    select = new JComboBox();
    select.addItem(NONE);
    select.addItem(SSH);
    if (Environment.isUnix())
      select.addItem(RSH);

    select.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
	layout.show(rhPanel,
		    select.getSelectedItem() == NONE ? BLANK : LOGIN);
      }
    });

    blank = new JPanel();
    hostname = new OptionWidget.TextMenuWidget(v);

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints gc = new GridBagConstraints();
    gc.fill = gc.BOTH;
    userAtHost = new JPanel();
    userAtHost.setLayout(gridbag);
    username = new JTextField(6);
    username.setHorizontalAlignment(username.TRAILING);
    hostname.setFont(username.getFont());
    JLabel at = new JLabel("@");
    gridbag.setConstraints(username, gc);
    gridbag.setConstraints(at, gc);
    gridbag.setConstraints(hostname, gc);
    userAtHost.add(username);
    userAtHost.add(at);
    userAtHost.add(hostname);

    rhPanel.add(blank, BLANK);
    rhPanel.add(userAtHost, LOGIN);

    add(select);
    add(rhPanel);
  }

  public String getHostname() {
    return hostname.getOptionValue();
  }

  public String getUsername() {
    return username.getText();
  }

  public int getShell() {
    Object shell = select.getSelectedItem();
    if (shell == NONE) return LoginInfo.LOCAL;
    else if (shell == SSH) return LoginInfo.SSH;
    else if (shell == RSH) return LoginInfo.RSH;
    else return LoginInfo.UNDEFINED; // shouldn't happen!
  }

  public void setHostname(String h) {
    if (h == null) return;
    hostname.setOptionValue(h);
  }

  public void setUsername(String u) {
    if (u == null) return;
    username.setText(u);
  }

  public void setShell(int s) {
    String shell;

    if (s == LoginInfo.LOCAL)    shell = NONE;
    else if (s == LoginInfo.SSH) shell = SSH;
    else if (s == LoginInfo.RSH) shell = RSH;
    else return;

    select.setSelectedItem(shell);
    layout.show(rhPanel, shell == NONE ? BLANK : LOGIN);
  }

  public void setBackground(Color c) {
    super.setBackground(c);
    if (select != null) {
      select.setBackground(c);
      blank.setBackground(c);
      hostname.setBackground(c);
      userAtHost.setBackground(c);
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -