예제 #1
0
 /** Add a search result to display. */
 public void addResult(final Result result, boolean focus) {
   KWTSelectableLabel selectable = new KWTSelectableLabel(result.title);
   selectable.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           // when the item is selected.
           root.setCurrentPanel(root.moreInfoPanel);
           root.moreInfoPanel.setResult(result);
         }
       });
   resultPanel.add(selectable);
   if (focus) {
     selectable.requestFocus();
   }
   resultPanel.add(new KLabel(result.summary));
 }
예제 #2
0
  public SearchPanel(UIRoot root) {
    this.root = root;
    searchField = new KTextField(20);
    final KButton searchBtn = new KButton("Search");
    final KLabel label = new KLabel("Search:");

    searchField.setBorder(new KLineBorder(1, true));
    label.setFont(res.getFont(KFontFamilyName.MONOSPACE, 30));
    resultPanel.setLayout(new GridLayout(DEFAULT_SEARCH_SIZE * 2, 1));

    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weighty = 0;
    gbc.weightx = 0;
    gbc.insets = new Insets(10, 10, 10, 10);
    add(label, gbc);
    gbc.gridx = 1;
    gbc.ipadx = 300;
    add(searchField, gbc);
    gbc.gridx = 2;
    add(searchBtn, gbc);
    // setup search panel.
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridy = 1;
    gbc.gridx = 0;
    gbc.gridwidth = 0;
    gbc.weighty = 1.0;
    gbc.weightx = 3;
    gbc.ipady = 300;
    gbc.insets = new Insets(25, 25, 25, 25);
    add(resultPanel, gbc);

    searchField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            String searchTerm = searchField.getText();
            searchField.setText("");
            currentPage = 0;
            currentSearch = searchTerm;
            search(searchTerm);
            searchField.repaint();
            resultPanel.repaint();
          }
        });
    root.searchPanel = this;
  }