Example usage for java.awt BorderLayout PAGE_START

List of usage examples for java.awt BorderLayout PAGE_START

Introduction

In this page you can find the example usage for java.awt BorderLayout PAGE_START.

Prototype

String PAGE_START

To view the source code for java.awt BorderLayout PAGE_START.

Click Source Link

Document

The component comes before the first line of the layout's content.

Usage

From source file:org.owasp.jbrofuzz.fuzz.ui.FuzzingPanel.java

/**
 * <p>/*  w  w  w  . j ava  2s  . c  om*/
 * This constructor is used for the " Fuzzing " panel that resides under the
 * FrameWindow, within the corresponding tabbed panel.
 * </p>
 * 
 * 
 * @param mWindow
 *            FrameWindow
 */
public FuzzingPanel(final JBroFuzzWindow mWindow) {

    super(" Fuzzing ", mWindow);

    counter = 0;
    payload = "";
    stopped = true;

    // Set the enabled options: Start, Stop, Pause, Add, Remove
    setOptionsAvailable(true, false, false, true, false);

    // The Target panel
    final JPanel targetPanel = new JPanel(new BorderLayout());
    targetPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(" Target "),
            BorderFactory.createEmptyBorder(1, 1, 1, 1)));

    urlField = new JTextField();
    urlField.setEditable(true);
    urlField.setVisible(true);
    urlField.setFont(new Font("Verdana", Font.BOLD, 12));
    urlField.setToolTipText("[{Protocol} :// {Host} [:{Port}]]");
    urlField.setMargin(new Insets(1, 1, 1, 1));
    urlField.setBackground(Color.WHITE);
    urlField.setForeground(Color.BLACK);

    requestPane = createEditablePane();

    // Right click: Cut, Copy, Paste, Select All
    AbstractPanel.popupText(urlField, true, true, true, true);

    targetPanel.add(urlField);

    // The fuzzers panel
    fuzzersPanel = new FuzzersPanel(this);

    // The on the wire panel
    final JPanel onTheWirePanel = new JPanel();
    onTheWirePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(" Requests "),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    mWireTextArea = new WireTextArea();

    // Right click: Cut, Copy, Paste, Select All
    RightClickPopups.rightClickOnTheWireTextComponent(this, mWireTextArea);

    final JScrollPane consoleScrollPane = new JScrollPane(mWireTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    onTheWirePanel.setLayout(new BorderLayout());
    onTheWirePanel.add(consoleScrollPane, BorderLayout.CENTER);

    // Set the scroll areas
    topPanel = new JPanel(new BorderLayout());
    topPanel.add(targetPanel, BorderLayout.PAGE_START);
    topPanel.add(createScrollingPanel(" Request ", requestPane), BorderLayout.CENTER);

    // create the outlining tabbed pane
    fuzzerWindowPane = new JTabbedPane();

    bottomPane = new FuzzSplitPane(FuzzSplitPane.HORIZONTAL_SPLIT, FuzzSplitPane.FUZZ_BOTTOM);

    bottomPane.setLeftComponent(fuzzersPanel);
    transformsPanel = new TransformsPanel(this);
    bottomPane.setRightComponent(transformsPanel);

    mainPane = new FuzzSplitPane(FuzzSplitPane.VERTICAL_SPLIT, FuzzSplitPane.FUZZ_MAIN);
    mainPane.setOneTouchExpandable(false);
    mainPane.setTopComponent(topPanel);
    mainPane.setBottomComponent(bottomPane);

    // Allow for all areas to be resized to even not be seen
    topPanel.setMinimumSize(JBroFuzzFormat.ZERO_DIM);
    bottomPane.setMinimumSize(JBroFuzzFormat.ZERO_DIM);

    // Create the outputPanel
    outputPanel = new OutputPanel(this);

    // add the respective panes/panels to the tabbed pane
    fuzzerWindowPane.addTab("Input", mainPane);
    fuzzerWindowPane.addTab("Output", outputPanel);
    fuzzerWindowPane.addTab("On the wire", onTheWirePanel);
    add(fuzzerWindowPane, BorderLayout.CENTER);

    // Display the last displayed url/request
    setTextURL(JBroFuzz.PREFS.get(JBroFuzzPrefs.TEXT_URL, ""));
    setTextRequest(JBroFuzz.PREFS.get(JBroFuzzPrefs.TEXT_REQUEST, ""));
}

From source file:com.raphfrk.craftproxyclient.gui.CraftProxyGUI.java

public CraftProxyGUI(String buildId) {

    pf = new PropertiesFile("CraftProxyClientGUI.txt");

    try {// w  w w  . j  a v  a  2s  .  c om
        pf.load();
    } catch (IOException e) {
        JOptionPane.showMessageDialog(CraftProxyGUI.this, "Unable to open settings file");
    }

    String defaultHostname = pf.getString("connect_hostname", "");
    int defaultPort = pf.getInt("connect_port", 20000);
    int listenPort = pf.getInt("listen_port", 25565);
    int desired = pf.getInt("cache_size", 48);

    try {
        pf.save();
    } catch (IOException e) {
        JOptionPane.showMessageDialog(CraftProxyGUI.this, "Unable to save settings file");
    }

    setTitle("CraftProxyClient Local (" + buildId + ")");
    setSize(500, 375);
    setLocation(40, 150);

    topPanel.setLayout(new BorderLayout());
    topPanel.setBorder(new TitledBorder("Remote Server"));
    topPanel.setBackground(Color.WHITE);
    secondPanel.setLayout(new BorderLayout());
    secondPanel.setBorder(new TitledBorder("Local Server"));
    secondPanel.setBackground(Color.WHITE);

    serverName = new JTextField(defaultHostname, 20);
    TitledBorder border = new TitledBorder("Name");
    serverName.setBorder(border);
    serverName.addActionListener(this);

    portNum = new JTextField(Integer.toString(defaultPort), 6);
    border = new TitledBorder("Port");
    portNum.setBorder(border);
    portNum.addActionListener(this);

    localServerName = new JLabel("localhost");
    localServerName.setBackground(Color.GRAY);
    border = new TitledBorder("Name");
    localServerName.setBorder(border);

    localServerPortnum = new JTextField(Integer.toString(listenPort), 6);
    border = new TitledBorder("Port");
    localServerPortnum.setBorder(border);
    localServerPortnum.addActionListener(this);

    topPanel.add(serverName, BorderLayout.CENTER);
    topPanel.add(portNum, BorderLayout.LINE_END);

    secondPanel.setLayout(new BorderLayout());
    secondPanel.add(localServerName, BorderLayout.CENTER);
    secondPanel.add(localServerPortnum, BorderLayout.LINE_END);

    combinedTop.setLayout(new BorderLayout());
    combinedTop.add(topPanel, BorderLayout.CENTER);
    combinedTop.add(secondPanel, BorderLayout.SOUTH);

    currentSize = new JTextField("Unknown");
    currentSize.setBorder(new TitledBorder("Current Size (MB)"));
    currentSize.setEditable(false);

    desiredSize = new JTextField(Integer.toString(desired));
    desiredSize.setBorder(new TitledBorder("Max Size (MB)"));

    connect = new JButton(buttonText);
    connect.addActionListener(this);

    filePanel = new JPanel();
    filePanel.setLayout(new BorderLayout());
    JPanel fileLinePanel = new JPanel();
    fileLinePanel.setBorder(new TitledBorder("Cache Size"));
    fileLinePanel.setLayout(new GridLayout(1, 3));
    fileLinePanel.add(currentSize);
    fileLinePanel.add(desiredSize);
    filePanel.add(fileLinePanel, BorderLayout.CENTER);
    filePanel.add(connect, BorderLayout.PAGE_END);

    info = new JLabel();
    border = new TitledBorder("Status");
    info.setBorder(border);

    setLayout(new BorderLayout());
    add(combinedTop, BorderLayout.PAGE_START);
    add(info, BorderLayout.CENTER);
    add(filePanel, BorderLayout.PAGE_END);

    this.setResizable(false);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    this.addWindowListener(this);

}

From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java

/**
 * /*from ww  w . j ava  2s . c  om*/
 */
protected void setupTablePane() {
    tablePane.add(table.getTableHeader(), BorderLayout.PAGE_START);

    Component comp = table.getColumnCount() > 3 ? new JScrollPane(table,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) : table;
    tablePane.add(comp, BorderLayout.CENTER);

}

From source file:Main.java

public Main() {
    super(new BorderLayout());

    // Create and populate the list model.
    listModel = new DefaultListModel();
    listModel.addElement("Whistler, Canada");
    listModel.addElement("Jackson Hole, Wyoming");
    listModel.addElement("Squaw Valley, California");
    listModel.addElement("Telluride, Colorado");
    listModel.addElement("Taos, New Mexico");
    listModel.addElement("Snowbird, Utah");
    listModel.addElement("Chamonix, France");
    listModel.addElement("Banff, Canada");
    listModel.addElement("Arapahoe Basin, Colorado");
    listModel.addElement("Kirkwood, California");
    listModel.addElement("Sun Valley, Idaho");
    listModel.addListDataListener(new MyListDataListener());

    // Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setSelectedIndex(0);//from   ww w.  ja va2s .c o  m
    list.addListSelectionListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);

    // Create the list-modifying buttons.
    addButton = new JButton(addString);
    addButton.setActionCommand(addString);
    addButton.addActionListener(new AddButtonListener());

    deleteButton = new JButton(deleteString);
    deleteButton.setActionCommand(deleteString);
    deleteButton.addActionListener(new DeleteButtonListener());

    ImageIcon icon = createImageIcon("Up16");
    if (icon != null) {
        upButton = new JButton(icon);
        upButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
        upButton = new JButton("Move up");
    }
    upButton.setToolTipText("Move the currently selected list item higher.");
    upButton.setActionCommand(upString);
    upButton.addActionListener(new UpDownListener());

    icon = createImageIcon("Down16");
    if (icon != null) {
        downButton = new JButton(icon);
        downButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
        downButton = new JButton("Move down");
    }
    downButton.setToolTipText("Move the currently selected list item lower.");
    downButton.setActionCommand(downString);
    downButton.addActionListener(new UpDownListener());

    JPanel upDownPanel = new JPanel(new GridLayout(2, 1));
    upDownPanel.add(upButton);
    upDownPanel.add(downButton);

    // Create the text field for entering new names.
    nameField = new JTextField(15);
    nameField.addActionListener(new AddButtonListener());
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();
    nameField.setText(name);

    // Create a control panel, using the default FlowLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.add(nameField);
    buttonPane.add(addButton);
    buttonPane.add(deleteButton);
    buttonPane.add(upDownPanel);

    // Create the log for reporting list data events.
    log = new JTextArea(10, 20);
    JScrollPane logScrollPane = new JScrollPane(log);

    // Create a split pane for the log and the list.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, listScrollPane, logScrollPane);
    splitPane.setResizeWeight(0.5);

    // Put everything together.
    add(buttonPane, BorderLayout.PAGE_START);
    add(splitPane, BorderLayout.CENTER);
}

From source file:components.TextSamplerDemo.java

public TextSamplerDemo() {
    setLayout(new BorderLayout());

    //Create a regular text field.
    JTextField textField = new JTextField(10);
    textField.setActionCommand(textFieldString);
    textField.addActionListener(this);

    //Create a password field.
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.setActionCommand(passwordFieldString);
    passwordField.addActionListener(this);

    //Create a formatted text field.
    JFormattedTextField ftf = new JFormattedTextField(java.util.Calendar.getInstance().getTime());
    ftf.setActionCommand(textFieldString);
    ftf.addActionListener(this);

    //Create some labels for the fields.
    JLabel textFieldLabel = new JLabel(textFieldString + ": ");
    textFieldLabel.setLabelFor(textField);
    JLabel passwordFieldLabel = new JLabel(passwordFieldString + ": ");
    passwordFieldLabel.setLabelFor(passwordField);
    JLabel ftfLabel = new JLabel(ftfString + ": ");
    ftfLabel.setLabelFor(ftf);//  w  ww  .  j  a v a 2 s  .  c  o m

    //Create a label to put messages during an action event.
    actionLabel = new JLabel("Type text in a field and press Enter.");
    actionLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));

    //Lay out the text controls and the labels.
    JPanel textControlsPane = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    textControlsPane.setLayout(gridbag);

    JLabel[] labels = { textFieldLabel, passwordFieldLabel, ftfLabel };
    JTextField[] textFields = { textField, passwordField, ftf };
    addLabelTextRows(labels, textFields, gridbag, textControlsPane);

    c.gridwidth = GridBagConstraints.REMAINDER; //last
    c.anchor = GridBagConstraints.WEST;
    c.weightx = 1.0;
    textControlsPane.add(actionLabel, c);
    textControlsPane.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Text Fields"), BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Create a text area.
    JTextArea textArea = new JTextArea("This is an editable JTextArea. "
            + "A text area is a \"plain\" text component, " + "which means that although it can display text "
            + "in any font, all of the text is in the same font.");
    textArea.setFont(new Font("Serif", Font.ITALIC, 16));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(250, 250));
    areaScrollPane.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Plain Text"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)),
            areaScrollPane.getBorder()));

    //Create an editor pane.
    JEditorPane editorPane = createEditorPane();
    JScrollPane editorScrollPane = new JScrollPane(editorPane);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(250, 145));
    editorScrollPane.setMinimumSize(new Dimension(10, 10));

    //Create a text pane.
    JTextPane textPane = createTextPane();
    JScrollPane paneScrollPane = new JScrollPane(textPane);
    paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    paneScrollPane.setPreferredSize(new Dimension(250, 155));
    paneScrollPane.setMinimumSize(new Dimension(10, 10));

    //Put the editor pane and the text pane in a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editorScrollPane, paneScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.5);
    JPanel rightPane = new JPanel(new GridLayout(1, 0));
    rightPane.add(splitPane);
    rightPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Styled Text"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Put everything together.
    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(textControlsPane, BorderLayout.PAGE_START);
    leftPane.add(areaScrollPane, BorderLayout.CENTER);

    add(leftPane, BorderLayout.LINE_START);
    add(rightPane, BorderLayout.LINE_END);
}

From source file:ListDataEventDemo.java

public ListDataEventDemo() {
    super(new BorderLayout());

    // Create and populate the list model.
    listModel = new DefaultListModel();
    listModel.addElement("Whistler, Canada");
    listModel.addElement("Jackson Hole, Wyoming");
    listModel.addElement("Squaw Valley, California");
    listModel.addElement("Telluride, Colorado");
    listModel.addElement("Taos, New Mexico");
    listModel.addElement("Snowbird, Utah");
    listModel.addElement("Chamonix, France");
    listModel.addElement("Banff, Canada");
    listModel.addElement("Arapahoe Basin, Colorado");
    listModel.addElement("Kirkwood, California");
    listModel.addElement("Sun Valley, Idaho");
    listModel.addListDataListener(new MyListDataListener());

    // Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setSelectedIndex(0);/*  ww w  . j a v a2s . com*/
    list.addListSelectionListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);

    // Create the list-modifying buttons.
    addButton = new JButton(addString);
    addButton.setActionCommand(addString);
    addButton.addActionListener(new AddButtonListener());

    deleteButton = new JButton(deleteString);
    deleteButton.setActionCommand(deleteString);
    deleteButton.addActionListener(new DeleteButtonListener());

    ImageIcon icon = createImageIcon("Up16");
    if (icon != null) {
        upButton = new JButton(icon);
        upButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
        upButton = new JButton("Move up");
    }
    upButton.setToolTipText("Move the currently selected list item higher.");
    upButton.setActionCommand(upString);
    upButton.addActionListener(new UpDownListener());

    icon = createImageIcon("Down16");
    if (icon != null) {
        downButton = new JButton(icon);
        downButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
        downButton = new JButton("Move down");
    }
    downButton.setToolTipText("Move the currently selected list item lower.");
    downButton.setActionCommand(downString);
    downButton.addActionListener(new UpDownListener());

    JPanel upDownPanel = new JPanel(new GridLayout(2, 1));
    upDownPanel.add(upButton);
    upDownPanel.add(downButton);

    // Create the text field for entering new names.
    nameField = new JTextField(15);
    nameField.addActionListener(new AddButtonListener());
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();
    nameField.setText(name);

    // Create a control panel, using the default FlowLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.add(nameField);
    buttonPane.add(addButton);
    buttonPane.add(deleteButton);
    buttonPane.add(upDownPanel);

    // Create the log for reporting list data events.
    log = new JTextArea(10, 20);
    JScrollPane logScrollPane = new JScrollPane(log);

    // Create a split pane for the log and the list.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, listScrollPane, logScrollPane);
    splitPane.setResizeWeight(0.5);

    // Put everything together.
    add(buttonPane, BorderLayout.PAGE_START);
    add(splitPane, BorderLayout.CENTER);
}

From source file:sanger.team16.gui.genevar.eqtl.snp.CisEQTLSNPPane.java

private BaseJPane setMatchedFeaturePanel() {
    BaseJPane panel = new BaseJPane("Genotype-Expression Pairs");
    //Study study = (Study) cbStudy.getSelectedItem();

    // ------------------ Panel p0 (start) ------------------ //
    BaseJPane p0 = new BaseJPane();

    p0.add(new JLabel("Study: "));
    p0.add(this.getJLabeledSelectedItem(cbStudy));

    p0.setBaseSpringBoxTrailing();//from  w w w.  j  a  va 2  s . co  m
    panel.add(p0);
    // ------------------ Panel p0 (end) ------------------ //

    // ------------------ Panel p1 (start) ------------------ //
    List<MatchedFeature> matchedFeatures = this.getMatchedFeaturesGxE(study.getId());
    this.matchedFeatureTableModel = new MatchedFeatureTableModel(matchedFeatures);
    this.matchedFeatureTable = matchedFeatureTableModel.getTable(); //TODO

    BaseJPane p1 = new BaseJPane();
    p1.setLayout(new BorderLayout());
    p1.add(matchedFeatureTable.getTableHeader(), BorderLayout.PAGE_START);
    p1.add(matchedFeatureTable, BorderLayout.CENTER);

    //p0.setBaseSpringGrid(1, 1);
    panel.add(p1);
    // ------------------ Panel p1 (end) ------------------ //

    panel.setBaseSpringGrid(1);
    return panel;
}

From source file:sanger.team16.gui.genevar.mqtl.snp.CisMQTLSNPPane.java

private BaseJPane setMatchedFeaturePanel() {
    BaseJPane panel = new BaseJPane("Genotype-Methylation Pairs");
    //Study study = (Study) cbStudy.getSelectedItem();

    // ------------------ Panel p0 (start) ------------------ //
    BaseJPane p0 = new BaseJPane();

    p0.add(new JLabel("Study: "));
    p0.add(this.getJLabeledSelectedItem(cbStudy));

    p0.setBaseSpringBoxTrailing();//ww  w. ja  va 2  s  .  c  o m
    panel.add(p0);
    // ------------------ Panel p0 (end) ------------------ //

    // ------------------ Panel p1 (start) ------------------ //
    List<MatchedFeature> matchedFeatures = this.getMatchedFeaturesGxM(study.getId());
    this.matchedFeatureTableModel = new MatchedFeatureTableModel(matchedFeatures);
    this.matchedFeatureTable = matchedFeatureTableModel.getTable(); //TODO

    BaseJPane p1 = new BaseJPane();
    p1.setLayout(new BorderLayout());
    p1.add(matchedFeatureTable.getTableHeader(), BorderLayout.PAGE_START);
    p1.add(matchedFeatureTable, BorderLayout.CENTER);

    //p0.setBaseSpringGrid(1, 1);
    panel.add(p1);
    // ------------------ Panel p1 (end) ------------------ //

    panel.setBaseSpringGrid(1);
    return panel;
}

From source file:Main.java

public Main() {
    super(new BorderLayout());

    //Create and populate the list model.
    listModel = new DefaultListModel();
    listModel.addElement("Whistler, Canada");
    listModel.addElement("Jackson Hole, Wyoming");
    listModel.addElement("Squaw Valley, California");
    listModel.addElement("Telluride, Colorado");
    listModel.addElement("Taos, New Mexico");
    listModel.addElement("Snowbird, Utah");
    listModel.addElement("Chamonix, France");
    listModel.addElement("Banff, Canada");
    listModel.addElement("Arapahoe Basin, Colorado");
    listModel.addElement("Kirkwood, California");
    listModel.addElement("Sun Valley, Idaho");
    listModel.addListDataListener(new MyListDataListener());

    //Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setSelectedIndex(0);/*from  w w  w .  j av a 2s. c om*/
    list.addListSelectionListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);

    //Create the list-modifying buttons.
    addButton = new JButton(addString);
    addButton.setActionCommand(addString);
    addButton.addActionListener(new AddButtonListener());

    deleteButton = new JButton(deleteString);
    deleteButton.setActionCommand(deleteString);
    deleteButton.addActionListener(new DeleteButtonListener());

    ImageIcon icon = createImageIcon("Up16");
    if (icon != null) {
        upButton = new JButton(icon);
        upButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
        upButton = new JButton("Move up");
    }
    upButton.setToolTipText("Move the currently selected list item higher.");
    upButton.setActionCommand(upString);
    upButton.addActionListener(new UpDownListener());

    icon = createImageIcon("Down16");
    if (icon != null) {
        downButton = new JButton(icon);
        downButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
        downButton = new JButton("Move down");
    }
    downButton.setToolTipText("Move the currently selected list item lower.");
    downButton.setActionCommand(downString);
    downButton.addActionListener(new UpDownListener());

    JPanel upDownPanel = new JPanel(new GridLayout(2, 1));
    upDownPanel.add(upButton);
    upDownPanel.add(downButton);

    //Create the text field for entering new names.
    nameField = new JTextField(15);
    nameField.addActionListener(new AddButtonListener());
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();
    nameField.setText(name);

    //Create a control panel, using the default FlowLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.add(nameField);
    buttonPane.add(addButton);
    buttonPane.add(deleteButton);
    buttonPane.add(upDownPanel);

    //Create the log for reporting list data events.
    log = new JTextArea(10, 20);
    JScrollPane logScrollPane = new JScrollPane(log);

    //Create a split pane for the log and the list.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, listScrollPane, logScrollPane);
    splitPane.setResizeWeight(0.5);

    //Put everything together.
    add(buttonPane, BorderLayout.PAGE_START);
    add(splitPane, BorderLayout.CENTER);
}

From source file:com.tascape.qa.th.android.driver.App.java

/**
 * The method starts a GUI to let an user inspect element tree and take screenshot when the user is interacting
 * with the app-under-test manually. Please make sure to set timeout long enough for manual interaction.
 *
 * @param timeoutMinutes timeout in minutes to fail the manual steps
 *
 * @throws Exception if case of error/*from  w w w . ja  v a 2s  .co m*/
 */
public void interactManually(int timeoutMinutes) throws Exception {
    LOG.info("Start manual UI interaction");
    long end = System.currentTimeMillis() + timeoutMinutes * 60000L;

    AtomicBoolean visible = new AtomicBoolean(true);
    AtomicBoolean pass = new AtomicBoolean(false);
    String tName = Thread.currentThread().getName() + "m";
    SwingUtilities.invokeLater(() -> {
        JDialog jd = new JDialog((JFrame) null, "Manual Device UI Interaction - " + device.getProductDetail());
        jd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

        JPanel jpContent = new JPanel(new BorderLayout());
        jd.setContentPane(jpContent);
        jpContent.setPreferredSize(new Dimension(1088, 828));
        jpContent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        JPanel jpInfo = new JPanel();
        jpContent.add(jpInfo, BorderLayout.PAGE_START);
        jpInfo.setLayout(new BorderLayout());
        {
            JButton jb = new JButton("PASS");
            jb.setForeground(Color.green.darker());
            jb.setFont(jb.getFont().deriveFont(Font.BOLD));
            jpInfo.add(jb, BorderLayout.LINE_START);
            jb.addActionListener(event -> {
                pass.set(true);
                jd.dispose();
                visible.set(false);
            });
        }
        {
            JButton jb = new JButton("FAIL");
            jb.setForeground(Color.red);
            jb.setFont(jb.getFont().deriveFont(Font.BOLD));
            jpInfo.add(jb, BorderLayout.LINE_END);
            jb.addActionListener(event -> {
                pass.set(false);
                jd.dispose();
                visible.set(false);
            });
        }

        JLabel jlTimeout = new JLabel("xxx seconds left", SwingConstants.CENTER);
        jpInfo.add(jlTimeout, BorderLayout.CENTER);
        jpInfo.add(jlTimeout, BorderLayout.CENTER);
        new SwingWorker<Long, Long>() {
            @Override
            protected Long doInBackground() throws Exception {
                while (System.currentTimeMillis() < end) {
                    Thread.sleep(1000);
                    long left = (end - System.currentTimeMillis()) / 1000;
                    this.publish(left);
                }
                return 0L;
            }

            @Override
            protected void process(List<Long> chunks) {
                Long l = chunks.get(chunks.size() - 1);
                jlTimeout.setText(l + " seconds left");
                if (l < 850) {
                    jlTimeout.setForeground(Color.red);
                }
            }
        }.execute();

        JPanel jpResponse = new JPanel(new BorderLayout());
        JPanel jpProgress = new JPanel(new BorderLayout());
        jpResponse.add(jpProgress, BorderLayout.PAGE_START);

        JTextArea jtaJson = new JTextArea();
        jtaJson.setEditable(false);
        jtaJson.setTabSize(4);
        Font font = jtaJson.getFont();
        jtaJson.setFont(new Font("Courier New", font.getStyle(), font.getSize()));

        JTree jtView = new JTree();

        JTabbedPane jtp = new JTabbedPane();
        jtp.add("tree", new JScrollPane(jtView));
        jtp.add("json", new JScrollPane(jtaJson));

        jpResponse.add(jtp, BorderLayout.CENTER);

        JPanel jpScreen = new JPanel();
        jpScreen.setMinimumSize(new Dimension(200, 200));
        jpScreen.setLayout(new BoxLayout(jpScreen, BoxLayout.PAGE_AXIS));
        JScrollPane jsp1 = new JScrollPane(jpScreen);
        jpResponse.add(jsp1, BorderLayout.LINE_START);

        JPanel jpJs = new JPanel(new BorderLayout());
        JTextArea jtaJs = new JTextArea();
        jpJs.add(new JScrollPane(jtaJs), BorderLayout.CENTER);

        JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jpResponse, jpJs);
        jSplitPane.setResizeWeight(0.88);
        jpContent.add(jSplitPane, BorderLayout.CENTER);

        JPanel jpLog = new JPanel();
        jpLog.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
        jpLog.setLayout(new BoxLayout(jpLog, BoxLayout.LINE_AXIS));

        JCheckBox jcbTap = new JCheckBox("Enable Click", null, false);
        jpLog.add(jcbTap);
        jpLog.add(Box.createHorizontalStrut(8));

        JButton jbLogUi = new JButton("Log Screen");
        jpResponse.add(jpLog, BorderLayout.PAGE_END);
        {
            jpLog.add(jbLogUi);
            jbLogUi.addActionListener((ActionEvent event) -> {
                jtaJson.setText("waiting for screenshot...");
                Thread t = new Thread(tName) {
                    @Override
                    public void run() {
                        LOG.debug("\n\n");
                        try {
                            WindowHierarchy wh = device.loadWindowHierarchy();
                            jtView.setModel(getModel(wh));

                            jtaJson.setText("");
                            jtaJson.append(wh.root.toJson().toString(2));
                            jtaJson.append("\n");

                            File png = device.takeDeviceScreenshot();
                            BufferedImage image = ImageIO.read(png);

                            int w = device.getDisplayWidth();
                            int h = device.getDisplayHeight();

                            BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                            Graphics2D g2 = resizedImg.createGraphics();
                            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                            g2.drawImage(image, 0, 0, w, h, null);
                            g2.dispose();

                            JLabel jLabel = new JLabel(new ImageIcon(resizedImg));
                            jpScreen.removeAll();
                            jsp1.setPreferredSize(new Dimension(w + 30, h));
                            jpScreen.add(jLabel);

                            jLabel.addMouseListener(new MouseAdapter() {
                                @Override
                                public void mouseClicked(MouseEvent e) {
                                    LOG.debug("clicked at {},{}", e.getPoint().getX(), e.getPoint().getY());
                                    if (jcbTap.isSelected()) {
                                        device.click(e.getPoint().x, e.getPoint().y);
                                        device.waitForIdle();
                                        jbLogUi.doClick();
                                    }
                                }
                            });
                        } catch (Exception ex) {
                            LOG.error("Cannot log screen", ex);
                            jtaJson.append("Cannot log screen");
                        }
                        jtaJson.append("\n\n\n");
                        LOG.debug("\n\n");

                        jd.setSize(jd.getBounds().width + 1, jd.getBounds().height + 1);
                        jd.setSize(jd.getBounds().width - 1, jd.getBounds().height - 1);
                    }
                };
                t.start();
            });
        }
        jpLog.add(Box.createHorizontalStrut(38));
        {
            JButton jbLogMsg = new JButton("Log Message");
            jpLog.add(jbLogMsg);
            JTextField jtMsg = new JTextField(10);
            jpLog.add(jtMsg);
            jtMsg.addFocusListener(new FocusListener() {
                @Override
                public void focusLost(final FocusEvent pE) {
                }

                @Override
                public void focusGained(final FocusEvent pE) {
                    jtMsg.selectAll();
                }
            });
            jtMsg.addKeyListener(new KeyAdapter() {
                @Override
                public void keyPressed(java.awt.event.KeyEvent e) {
                    if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
                        jbLogMsg.doClick();
                    }
                }
            });
            jbLogMsg.addActionListener(event -> {
                Thread t = new Thread(tName) {
                    @Override
                    public void run() {
                        String msg = jtMsg.getText();
                        if (StringUtils.isNotBlank(msg)) {
                            LOG.info("{}", msg);
                            jtMsg.selectAll();
                        }
                    }
                };
                t.start();
                try {
                    t.join();
                } catch (InterruptedException ex) {
                    LOG.error("Cannot take screenshot", ex);
                }
                jtMsg.requestFocus();
            });
        }
        jpLog.add(Box.createHorizontalStrut(38));
        {
            JButton jbClear = new JButton("Clear");
            jpLog.add(jbClear);
            jbClear.addActionListener(event -> {
                jtaJson.setText("");
            });
        }

        JPanel jpAction = new JPanel();
        jpContent.add(jpAction, BorderLayout.PAGE_END);
        jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS));
        jpJs.add(jpAction, BorderLayout.PAGE_END);

        jd.pack();
        jd.setVisible(true);
        jd.setLocationRelativeTo(null);

        jbLogUi.doClick();
    });

    while (visible.get()) {
        if (System.currentTimeMillis() > end) {
            LOG.error("Manual UI interaction timeout");
            break;
        }
        Thread.sleep(500);
    }

    if (pass.get()) {
        LOG.info("Manual UI Interaction returns PASS");
    } else {
        Assert.fail("Manual UI Interaction returns FAIL");
    }
}