/** Method declaration */
  private void initGUI() {

    Panel pQuery = new Panel();
    Panel pCommand = new Panel();

    pResult = new Panel();

    pQuery.setLayout(new BorderLayout());
    pCommand.setLayout(new BorderLayout());
    pResult.setLayout(new BorderLayout());

    Font fFont = new Font("Dialog", Font.PLAIN, 12);

    txtCommand = new TextArea(5, 40);

    txtCommand.addKeyListener(this);

    txtResult = new TextArea(20, 40);

    txtCommand.setFont(fFont);
    txtResult.setFont(new Font("Courier", Font.PLAIN, 12));

    butExecute = new Button("Execute");
    butClear = new Button("Clear");

    butExecute.addActionListener(this);
    butClear.addActionListener(this);
    pCommand.add("East", butExecute);
    pCommand.add("West", butClear);
    pCommand.add("Center", txtCommand);

    gResult = new Grid();

    setLayout(new BorderLayout());
    pResult.add("Center", gResult);
    pQuery.add("North", pCommand);
    pQuery.add("Center", pResult);
    fMain.add("Center", pQuery);

    tTree = new Tree();

    // (ulrivo): screen with less than 640 width
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

    if (d.width >= 640) {
      tTree.setMinimumSize(new Dimension(200, 100));
    } else {
      tTree.setMinimumSize(new Dimension(80, 100));
    }

    gResult.setMinimumSize(new Dimension(200, 300));
    fMain.add("West", tTree);
    doLayout();
    fMain.pack();
  }
 private static void badFetch() {
   final JFrame frame = new JFrame("TestFetchWebGui");
   final JPanel outerPanel = new JPanel(), buttonPanel = new JPanel();
   final JButton fetchButton = new JButton("Fetch"), cancelButton = new JButton("Cancel");
   frame.add(outerPanel);
   outerPanel.setLayout(new BorderLayout());
   buttonPanel.setLayout(new GridLayout(2, 1));
   buttonPanel.add(fetchButton);
   buttonPanel.add(cancelButton);
   outerPanel.add(buttonPanel, BorderLayout.EAST);
   final TextArea textArea = new TextArea(25, 80);
   textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
   outerPanel.add(textArea, BorderLayout.WEST);
   fetchButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           for (String url : urls) {
             System.out.println("Fetching " + url);
             String page = getPage(url, 200);
             textArea.append(String.format("%-40s%7d%n", url, page.length()));
           }
         }
       });
   frame.pack();
   frame.setVisible(true);
 }
  public void initComponents() {
    /** ******************** The main container *************************** */
    Container container = this.getContentPane();
    container.setLayout(new BorderLayout());
    container.setBackground(Color.black);
    this.setSize(650, 600);
    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {}
        });

    /** ************************* MAIN PANEL ******************************* */
    mainPanel = new JPanel();
    // If put to False: we see the container's background
    mainPanel.setOpaque(false);
    mainPanel.setLayout(new BorderLayout());
    container.add(mainPanel, BorderLayout.CENTER);

    allmessagesTextArea = new TextArea();
    allmessagesTextArea.setEditable(false);
    allmessagesTextArea.setFont(new Font("Dialog", 1, 12));
    allmessagesTextArea.setForeground(Color.black);
    allmessagesTextArea.append("Select a session in the list to view its messages");
    mainPanel.add(allmessagesTextArea, BorderLayout.CENTER);

    sessionsList = new List();
    sessionsList.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            showMessages(e);
          }
        });
    sessionsList.setForeground(Color.black);
    sessionsList.setFont(new Font("Dialog", 1, 14));
    mainPanel.add(sessionsList, BorderLayout.WEST);

    okButton = new JButton("  OK  ");
    okButton.setToolTipText("Returns to the main frame");
    okButton.setFont(new Font("Dialog", 1, 16));
    okButton.setFocusPainted(false);
    okButton.setBackground(Color.lightGray);
    okButton.setBorder(new BevelBorder(BevelBorder.RAISED));
    okButton.setVerticalAlignment(SwingConstants.CENTER);
    okButton.setHorizontalAlignment(SwingConstants.CENTER);
    container.add(okButton, BorderLayout.SOUTH);
    okButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            setVisible(false);
          }
        });
  }
Beispiel #4
0
 /**
  * Adds one or two (side by side) text areas.
  *
  * @param text1 initial contents of the first text area
  * @param text2 initial contents of the second text area or null
  * @param rows the number of rows
  * @param columns the number of columns
  */
 public void addTextAreas(String text1, String text2, int rows, int columns) {
   if (textArea1 != null) return;
   Panel panel = new Panel();
   Font font = new Font("SansSerif", Font.PLAIN, 14);
   textArea1 = new TextArea(text1, rows, columns, TextArea.SCROLLBARS_NONE);
   if (IJ.isLinux()) textArea1.setBackground(Color.white);
   textArea1.setFont(font);
   textArea1.addTextListener(this);
   panel.add(textArea1);
   if (text2 != null) {
     textArea2 = new TextArea(text2, rows, columns, TextArea.SCROLLBARS_NONE);
     if (IJ.isLinux()) textArea2.setBackground(Color.white);
     textArea2.setFont(font);
     panel.add(textArea2);
   }
   c.gridx = 0;
   c.gridy = y;
   c.gridwidth = 2;
   c.anchor = GridBagConstraints.WEST;
   c.insets = getInsets(15, 20, 0, 0);
   grid.setConstraints(panel, c);
   add(panel);
   y++;
 }
 public void setTextFont(Font f) {
   ta.setFont(f);
 }
  private static void goodFetch() {
    final JFrame frame = new JFrame("TestFetchWebGui");
    final JPanel outerPanel = new JPanel(), buttonPanel = new JPanel();
    final JButton fetchButton = new JButton("Fetch"), cancelButton = new JButton("Cancel");
    frame.add(outerPanel);
    outerPanel.setLayout(new BorderLayout());
    buttonPanel.setLayout(new GridLayout(2, 1));
    buttonPanel.add(fetchButton);
    buttonPanel.add(cancelButton);
    outerPanel.add(buttonPanel, BorderLayout.EAST);
    final TextArea textArea = new TextArea(25, 80);
    textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
    outerPanel.add(textArea, BorderLayout.WEST);

    // (2) Add a progress bar
    JProgressBar progressBar = new JProgressBar(0, 100);
    outerPanel.add(progressBar, BorderLayout.SOUTH);

    // (1) Use a background thread, not the event thread, for work
    ArrayList<DownloadWorker> dw = new ArrayList<>();
    AtomicInteger count = new AtomicInteger();

    fetchButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dw.clear();
            count.set(0);
            progressBar.setValue(0);

            for (String url : urls) {
              DownloadWorker downloadTask = new DownloadWorker(textArea, url, count);
              dw.add(downloadTask);
            }

            for (DownloadWorker dlw : dw) {
              dlw.execute();
              dlw.addPropertyChangeListener(
                  new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent e) {
                      if ("progress".equals(e.getPropertyName())) {
                        progressBar.setValue((Integer) e.getNewValue());
                      }
                    }
                  });
            }
          }
        });

    // (3) Enable cancellation
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            for (DownloadWorker dlw : dw) {
              dlw.cancel(false);
            }
            textArea.append("Cancelled\n");
          }
        });
    frame.pack();
    frame.setVisible(true);
  }
  public babylonTextDialog(
      Frame parent,
      String myLabel,
      String contents,
      int columns,
      int rows,
      int scrollbars,
      boolean IsModal,
      String dismissString) {
    super(parent, myLabel, IsModal);

    parentFrame = parent;

    myLayout = new GridBagLayout();
    setLayout(myLayout);

    p = new Panel();
    p.setLayout(myLayout);

    textArea = new TextArea(contents, rows, columns, scrollbars);
    textArea.addKeyListener(this);
    textArea.setEditable(false);
    textArea.setFont(babylonPanel.smallFont);
    p.add(
        textArea,
        new babylonConstraints(
            0,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 0),
            0,
            0));

    dismissButton = new Button(dismissString);
    dismissButton.setFont(babylonPanel.smallFont);
    dismissButton.addActionListener(this);
    dismissButton.addKeyListener(this);
    p.add(
        dismissButton,
        new babylonConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    add(
        p,
        new babylonConstraints(
            0,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    pack();

    if ((parentFrame instanceof babylonWindow) || (parentFrame instanceof babylonServerWindow))
      babylonPanel.centerDialog(parentFrame, this);
    else babylonPanel.centerDialogOnScreen(this);

    addKeyListener(this);
    addWindowListener(this);
    setResizable(false);
    setVisible(true);
    dismissButton.requestFocus();
  }