示例#1
0
  public ServiceDialog(Image windowIconImage, String message, boolean serviceAvailable) {
    super(windowIconImage, SERVICE_TITLE);

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            finish();
          }
        });

    setLayout(new BorderLayout());
    setBackground(SystemColor.control);

    Panel p = new Panel(new FlowLayout(FlowLayout.LEFT, 15, 15));
    add("West", p); // $NON-NLS-1$

    Label c = new ImageLabel(SERVICE_ICON);
    c.setPreferredSize(new Dimension(48, 48));
    p.add(c);

    Panel tp = new Panel(new BorderLayout());
    add("Center", tp); // $NON-NLS-1$

    p = new Panel(new FlowLayout(FlowLayout.LEFT, 0, 15));
    tp.add("North", p); // $NON-NLS-1$
    Panel mp = new Panel(new BorderLayout());
    p.add(mp);

    mp.add("North", new Label(SERVICE_TITLE + ":")); // $NON-NLS-1$ //$NON-NLS-2$

    p = new Panel(new FlowLayout(FlowLayout.LEFT));
    mp.add("Center", p); // $NON-NLS-1$

    TextArea ta = new TextArea(message, 5, 70);
    ta.setEditable(false);

    ta.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            if (!m_focusRepaired) // OK button should be focused first
            {
              m_okButton.requestFocus();
            }
          }
        });

    ta.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              finish();
            }
          }
        });

    p.add(ta);

    if (!serviceAvailable) {
      tp.add("South", new Label(SERVICE_NOT_AVAILABLE)); // $NON-NLS-1$
    }

    p = new Panel(new FlowLayout(FlowLayout.RIGHT, 15, 15));
    m_okButton = new Button(Messages.getString("ok")); // $NON-NLS-1$
    m_okButton.setPreferredSize(new Dimension(73, 20));

    m_okButton.addFocusListener(
        new FocusAdapter() {

          @Override
          public void focusGained(FocusEvent e) {
            m_focusRepaired = true;
          }
        });

    m_okButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            finish();
          }
        });

    m_okButton.addKeyListener(
        new KeyAdapter() {

          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              finish();
            }
          }
        });
    p.add(m_okButton);
    add("South", p); // $NON-NLS-1$

    pack();

    int width = Math.max(getWidth(), MIN_H_SIZE);
    int height = Math.max(getHeight(), MIN_V_SIZE);

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    setBounds((screen.width - width) / 2, (screen.height - height) / 2, width, height);
  }