public void drop(DropTargetDropEvent dropTargetDropEvent) {
    resetGlassPane();

    Point p = list.getMousePosition();

    int dstRow = list.locationToIndex(p);

    int srcRow = list.locationToIndex(from);
    ProfileListModel m = (ProfileListModel) list.getModel();

    if (dstRow < 0) {
      dstRow = 0;
    }
    if (dstRow > m.getSize() - 1) {
      dstRow = m.getSize() - 1;
    }

    m.insertElementAt((File) m.getElementAt(srcRow), dstRow);
    if (dstRow <= srcRow) {
      m.removeElementAt(srcRow + 1);
      list.setSelectedIndex(dstRow);
    } else {
      m.removeElementAt(srcRow);
      list.setSelectedIndex(dstRow - 1);
    }
  }
Esempio n. 2
0
  /**
   * fill the Listbox with the list of games. Select the same game after filling that was selected
   * before if possible.
   */
  private void fillGameList(Vector<Game> withGames) {
    int oldIndex = lbGames.getSelectedIndex();
    // log.debug("list currently has "+lbGames.getModel().getSize()+" elements");

    Object temp = null;
    if (oldIndex >= 0) {
      try {
        temp = lbGames.getSelectedValue();
      } catch (Exception ex) {
      }
    }
    for (int i = 0; i < withGames.size(); i++) {
      lbGames.setListData(withGames);
    }
    btJoin.setEnabled((withGames.size() > 0));
    btView.setEnabled((withGames.size() > 0));
    if (oldIndex >= 0 && oldIndex < withGames.size()) {
      lbGames.setSelectedIndex(oldIndex);
      if (temp != null && !lbGames.getSelectedValue().equals(temp)) {
        lbGames.setSelectedIndex(-1);
      }
    }
    // log.debug("now it has "+lbGames.getModel().getSize()+" elements");
    this.updateUI();
  }
  /** Set the contents of the field selector list. */
  private void setupFieldSelector() {
    fieldListModel.clear();
    SortedSet<String> contents = new TreeSet<>();
    for (String s : metaData) {
      if (s.startsWith(Globals.SELECTOR_META_PREFIX)) {
        contents.add(s.substring(Globals.SELECTOR_META_PREFIX.length()));
      }
    }
    if (contents.isEmpty()) {
      // if nothing was added, put the default fields (as described in the help)
      fieldListModel.addElement("author");
      fieldListModel.addElement("journal");
      fieldListModel.addElement("keywords");
      fieldListModel.addElement("publisher");
    } else {
      for (String s : contents) {
        fieldListModel.addElement(s);
      }
    }

    if (currentField == null) {
      // if dialog is created for the whole database,
      // select the first field to avoid confusions in GUI usage
      fieldList.setSelectedIndex(0);
    } else {
      // a specific field has been chosen at the constructor
      // select this field
      int i = fieldListModel.indexOf(currentField);
      if (i != -1) {
        // field has been found in list, select it
        fieldList.setSelectedIndex(i);
      }
    }
  }
    /*----------------------------------------------------------------------*/
    public void actionPerformed(ActionEvent e) {
      SwingEditor.instance.setDirty(dirtyFlag);

      if (e.getSource() == add) {
        TileScript script = new FlavourText("");
        TileScriptEditor dialog =
            new TileScriptEditor(SwingEditor.instance, script, dirtyFlag, zone);
        if (dialog.getResult() != null) {
          SwingEditor.instance.setDirty(dirtyFlag);
          dataModel.add(dialog.getResult());
        }
      } else if (e.getSource() == delete) {
        int index = list.getSelectedIndex();
        if (index > -1) {
          SwingEditor.instance.setDirty(dirtyFlag);
          dataModel.remove(index);
        }
      } else if (e.getSource() == edit) {
        editListItem();
      } else if (e.getSource() == moveUp) {
        dataModel.moveUp(list.getSelectedIndex());
        list.setSelectedIndex(list.getSelectedIndex() - 1);
      } else if (e.getSource() == moveDown) {
        dataModel.moveDown(list.getSelectedIndex());
        list.setSelectedIndex(list.getSelectedIndex() + 1);
      }
    }
Esempio n. 5
0
 private void doDelete() {
   int k = contactList.getSelectedIndex();
   if (k != -1) {
     String oldname = (String) contactList.getSelectedValue();
     addrbook.remove(oldname);
     contactListModel.removeElementAt(k);
     if (contactListModel.getSize() > k) contactList.setSelectedIndex(k);
     else if (k - 1 >= 0) contactList.setSelectedIndex(k - 1);
   }
 }
Esempio n. 6
0
  /** Switches the JList to the next record */
  private void switchToNext() {
    // if at the last record
    if (list.getSelectedIndex() + 1 > list.getModel().getSize() - 1) {
      // Then go to the begenning
      list.setSelectedIndex(0);
    } else {
      // otherwise to to the next.
      list.setSelectedIndex(list.getSelectedIndex() + 1);
    }

    // Update the contact pane
    contactdatapane.populateTextBoxesWithRecord(list.getSelectedValue().toString());
    list.ensureIndexIsVisible(list.getSelectedIndex());
  }
  /** Updates the Rating-Lists */
  private void updateLists() {
    RatingComparator comperator = new RatingComparator();

    Vector<Rating> personalVector = new Vector<Rating>(mPlugin.getDatabase().getPersonalRatings());
    Collections.sort(personalVector, comperator);
    int index = mPersonalRatings.getSelectedIndex();
    mPersonalRatings.setListData(personalVector);
    mPersonalRatings.setSelectedIndex(index);

    Vector<Rating> overallVector = new Vector<Rating>(mPlugin.getDatabase().getServerRatings());
    Collections.sort(overallVector, comperator);
    index = mOverallRatings.getSelectedIndex();
    mOverallRatings.setListData(overallVector);
    mOverallRatings.setSelectedIndex(index);
  }
  /**
   * Shows the PopUp
   *
   * @param e MouseEvent
   */
  protected void showPopUpMenu(MouseEvent e) {
    if (!(e.getSource() instanceof JList)) {
      return;
    }

    JList list = (JList) e.getSource();

    int i = list.locationToIndex(e.getPoint());
    list.setSelectedIndex(i);

    JPopupMenu menu = new JPopupMenu();

    Rating selRating = (Rating) list.getSelectedValue();

    JMenuItem item = new JMenuItem(mLocalizer.msg("showDetails", "Show Details"));
    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            view();
          }
        });
    item.setFont(item.getFont().deriveFont(Font.BOLD));

    menu.add(item);
    menu.add(new ListAction(this, selRating.getTitle()));
    menu.add(new ShowDetailsAction(selRating.getRatingId()));

    menu.show(list, e.getX(), e.getY());
  }
Esempio n. 9
0
  public void makeInterface() {
    frame = new JFrame("俄罗斯方块多人对战");

    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.setResizable(false);

    listModel = new DefaultListModel();
    listModel.ensureCapacity(100);

    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setSelectedIndex(0);

    JButton exitButton = new JButton("Disconnect/Exit");
    exitButton.setActionCommand("exit");
    exitButton.addActionListener(this);

    JScrollPane listScroller = new JScrollPane(list);
    listScroller.setPreferredSize(new Dimension(250, 125));

    frame.getContentPane().add(listScroller, BorderLayout.CENTER);
    frame.getContentPane().add(exitButton, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(false);
  }
Esempio n. 10
0
 private void showStack(ThreadInfo tinfo, int selectFrame) {
   StackTraceListModel model = new StackTraceListModel(tinfo);
   stackModel = model;
   list.setModel(stackModel);
   list.setSelectedIndex(selectFrame);
   list.ensureIndexIsVisible(selectFrame);
 }
Esempio n. 11
0
 public NodeSelectionDialog(Frame owner, NodeLibrary library, NodeLibraryManager manager) {
   super(owner, "New Node", true);
   getRootPane().putClientProperty("Window.style", "small");
   JPanel panel = new JPanel(new BorderLayout());
   this.library = library;
   this.manager = manager;
   filteredNodeListModel = new FilteredNodeListModel(library, manager);
   searchField = new JTextField();
   searchField.putClientProperty("JTextField.variant", "search");
   EscapeListener escapeListener = new EscapeListener();
   searchField.addKeyListener(escapeListener);
   ArrowKeysListener arrowKeysListener = new ArrowKeysListener();
   searchField.addKeyListener(arrowKeysListener);
   SearchFieldChangeListener searchFieldChangeListener = new SearchFieldChangeListener();
   searchField.getDocument().addDocumentListener(searchFieldChangeListener);
   nodeList = new JList(filteredNodeListModel);
   DoubleClickListener doubleClickListener = new DoubleClickListener();
   nodeList.addMouseListener(doubleClickListener);
   nodeList.addKeyListener(escapeListener);
   nodeList.addKeyListener(arrowKeysListener);
   nodeList.setSelectedIndex(0);
   nodeList.setCellRenderer(new NodeRenderer());
   JScrollPane nodeScroll =
       new JScrollPane(
           nodeList,
           JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
           JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
   nodeScroll.setBorder(null);
   panel.add(searchField, BorderLayout.NORTH);
   panel.add(nodeScroll, BorderLayout.CENTER);
   setContentPane(panel);
   setSize(500, 400);
   SwingUtils.centerOnScreen(this);
 }
Esempio n. 12
0
  /**
   * @param owner the parent Window (Dialog or Frame)
   * @param frame the JabRef Frame
   * @param panel the currently selected BasePanel
   * @param modal should this dialog be modal?
   * @param metaData The metadata of the current database
   * @param fieldName the field this selector is initialized for. May be null.
   */
  public ContentSelectorDialog2(
      Window owner,
      JabRefFrame frame,
      BasePanel panel,
      boolean modal,
      MetaData metaData,
      String fieldName) {
    super(owner, Localization.lang("Setup selectors"));
    this.setModal(modal);
    this.metaData = metaData;
    this.frame = frame;
    this.panel = panel;
    this.currentField = fieldName;

    initLayout();

    setupFieldSelector();
    setupWordSelector();
    setupActions();
    Util.bindCloseDialogKeyToCancelAction(this.rootPane, cancel.getAction());
    int fieldInd = fieldListModel.indexOf(currentField);
    if (fieldInd >= 0) {
      fieldList.setSelectedIndex(fieldInd);
    }

    pack();
  }
Esempio n. 13
0
 private void newWordAction() {
   if (wordListModel.isEmpty() || !wordListModel.get(0).equals(WORD_FIRSTLINE_TEXT)) {
     wordListModel.add(0, WORD_FIRSTLINE_TEXT);
   }
   wordList.setSelectedIndex(0);
   wPane.getVerticalScrollBar().setValue(0);
 }
Esempio n. 14
0
  public void refresh() {
    model.refresh();

    if (model.getEventList().size() > 0 && contacts.getSelectedIndex() == -1) {
      contacts.setSelectedIndex(0);
    }
  }
  private void loadList(JList list) {
    list.removeAll();
    profiles = parentGenerator.getProfiles();
    DefaultListModel model = new DefaultListModel();
    int i = 0;
    int foundLastProfile = -1;
    for (Profile p : profiles) {

      // Check that this profile says it's for this machine
      if (ProfileUtils.shouldDisplay(p) || filterBox.isSelected()) model.addElement(p.toString());
      if (p.toString().equals(Base.preferences.get("lastGeneratorProfileSelected", "---"))) {
        Base.logger.fine("Selecting last used element: " + p);
        foundLastProfile = i;
      }
      i++;
    }
    list.setModel(model);
    list.clearSelection();
    if (foundLastProfile != -1) {
      list.setSelectedIndex(foundLastProfile);
      doneButton.setEnabled(true);
      doneButton.requestFocusInWindow();
      doneButton.setFocusPainted(true);
    }
  }
 /** Create a new archetype. */
 private void makeNewAchetype() {
   Archetype archetype = new Archetype();
   archetype.setName("New Archetype");
   listData.add(archetype);
   archetypeList.setSelectedIndex(listData.size() - 1);
   saveListAction.setEnabled(true);
 }
Esempio n. 17
0
  protected void init() {
    super.init();

    java.util.List<Macro> macros = new ArrayList<Macro>(MacroManager.getInstance().getMacros());
    Collections.sort(
        macros,
        new Comparator<Macro>() {
          public int compare(Macro macro1, Macro macro2) {
            String name1 = macro1.getName();
            String name2 = macro2.getName();
            if (!StringUtil.startsWithChar(name1, '/')) {
              name1 = ZERO + name1;
            }
            if (!StringUtil.startsWithChar(name2, '/')) {
              name2 = ZERO + name2;
            }
            return name1.compareToIgnoreCase(name2);
          }

          private final String ZERO = new String(new char[] {0});
        });
    for (Macro macro : macros) {
      myMacrosModel.addElement(new MacroWrapper(macro));
    }

    addListeners();
    if (myMacrosModel.size() > 0) {
      myMacrosList.setSelectedIndex(0);
    } else {
      setOKActionEnabled(false);
    }
  }
Esempio n. 18
0
 protected void highlightFirstResult() {
   if (resultsList.getModel().getSize() > 0) {
     resultsList.setSelectedIndex(0);
     resultsList.ensureIndexIsVisible(0);
     resultsList.requestFocus();
   }
 }
Esempio n. 19
0
  private void doSearch() {
    ExtensionSearch.Type type = ExtensionSearch.Type.All;

    if (Constant.messages
        .getString("search.toolbar.label.type.url")
        .equals(searchType.getSelectedItem())) {
      type = ExtensionSearch.Type.URL;
    } else if (Constant.messages
        .getString("search.toolbar.label.type.request")
        .equals(searchType.getSelectedItem())) {
      type = ExtensionSearch.Type.Request;
    } else if (Constant.messages
        .getString("search.toolbar.label.type.response")
        .equals(searchType.getSelectedItem())) {
      type = ExtensionSearch.Type.Response;
    } else if (Constant.messages
        .getString("search.toolbar.label.type.header")
        .equals(searchType.getSelectedItem())) {
      type = ExtensionSearch.Type.Header;
    } else if (Constant.messages
        .getString("search.toolbar.label.type.fuzz")
        .equals(searchType.getSelectedItem())) {
      type = ExtensionSearch.Type.Fuzz;
    }

    extension.search(regEx.getText(), type, false, chkInverse.isSelected());

    // Select first result
    if (resultsList.getModel().getSize() > 0) {
      resultsList.setSelectedIndex(0);
      resultsList.requestFocus();
    }
  }
Esempio n. 20
0
  private Component crearLista() {
    listModel = new DefaultListModel<String>();
    listModel.addElement("cerveza.png");
    listModel.addElement("pintxo.png");
    listModel.addElement("tigre1.png");
    listModel.addElement("tigre2.png");
    listModel.addElement("tigre3.png");
    listModel.addElement("tigre4.png");
    listModel.addElement("tigre5.png");
    listModel.addElement("tigre6.png");
    listModel.addElement("tigre7.png");
    listModel.addElement("tigre8.png");
    listModel.addElement("tigre9.png");
    listModel.addElement("tigre10.png");
    listModel.addElement("tigre11.png");
    listModel.addElement("tigre12.png");
    listModel.addElement("total.png");
    listModel.addElement("vino.png");

    lista = new JList<String>(listModel);
    lista.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lista.setSelectedIndex(0);
    // lista.addListSelectionListener(this);

    JScrollPane listScrollPane = new JScrollPane(lista);

    return listScrollPane;
  }
Esempio n. 21
0
  private void actualizarReferencias() {
    if (petList != null) {
      petList.setCellRenderer(null);
    }

    petList = new JList();
    petList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    paleta = imagen.getPaleta();

    // Elementos iniciales
    elementosMuestra = new DefaultListModel<String>();
    for (int i = 0; i < paleta.getValores().size(); i++) {
      elementosMuestra.addElement("" + i);
    }

    //		System.out.println("Referencias: " + paleta.getValores().size());
    petList.setModel(elementosMuestra);
    petList.setSelectedIndex(0);
    ColorListRenderer elem = new ColorListRenderer(this, imagen.getPaleta());
    elem.setPreferredSize(new Dimension(150, 30));
    petList.setCellRenderer(elem);
    //		panel_1.add(petList);
    scrollPane.setViewportView(petList);

    petList.updateUI();
  }
Esempio n. 22
0
    @Override
    @SuppressWarnings({"deprecation", "unchecked"}) // FIXME in Java7
    public void mousePressed(MouseEvent e) {
      if (!enabled && e.getClickCount() == 1 && !e.isConsumed()) {
        enabled = true;
      }

      if (enabled) {
        JList source = (JList) e.getSource();
        if ((e.getButton() == MouseEvent.BUTTON3 || e.isPopupTrigger())) {
          int index = source.locationToIndex(e.getPoint());
          BuildableType type = (BuildableType) source.getModel().getElementAt(index);
          getGUI().showColopediaPanel(type.getId());
        } else if ((e.getClickCount() > 1 && !e.isConsumed())) {
          DefaultListModel model = (DefaultListModel) buildQueueList.getModel();
          if (source.getSelectedIndex() == -1) {
            source.setSelectedIndex(source.locationToIndex(e.getPoint()));
          }
          for (Object type : source.getSelectedValues()) {
            if (add) {
              model.addElement(type);
            } else {
              model.removeElement(type);
            }
          }
          updateAllLists();
        }
      }
    }
Esempio n. 23
0
  public CreateObjectDialog(AppD app, SpreadsheetView view, int objectType) {

    super(app.getFrame(), false, app.getLocalization());
    this.app = app;
    this.objectType = objectType;
    this.table = (MyTableD) view.getSpreadsheetTable();
    cp = table.getCellRangeProcessor();
    selectedCellRanges = table.selectedCellRanges;

    boolean showApply = false;

    createGUI(title, "", false, 16, 1, false, false, false, showApply, DialogType.GeoGebraEditor);

    // this.btCancel.setVisible(false);

    createAdditionalGUI();

    updateGUI();

    isIniting = false;
    setLabels(null);
    // setTitle((String) model.getElementAt(objectType));

    // optionPane.add(inputPanel, BorderLayout.CENTER);
    typeList.setSelectedIndex(objectType);

    wrappedDialog.setResizable(true);
    centerOnScreen();
    btCancel.requestFocus();
    wrappedDialog.pack();
    wrappedDialog.addWindowFocusListener(this);
  }
Esempio n. 24
0
  public void refresh(Slice[] sliceData) {

    sliceListModel.clear();
    if (sliceData != null) sliceListModel.addAll(sliceData);
    sliceList.setSelectedIndex(0);
    updateDisplays();
  }
Esempio n. 25
0
  /** update our data */
  void updateData() {

    // find out which one is selected
    final int curSel = _myList.getSelectedIndex();

    // create an object to put the data into
    final Vector<WorldLocationHolder> list = new Vector<WorldLocationHolder>(0, 1);

    if (getPath() != null) {
      final int len = getPath().size();
      for (int i = 0; i < len; i++) {
        final WorldLocation thisLoc = getPath().getLocationAt(i);
        final WorldLocationHolder holder = new WorldLocationHolder(thisLoc, i + 1);
        list.add(holder);
      }
    }

    // and put the data into the list
    _myList.setListData(list);

    // select the previous item
    if (curSel != -1 && curSel < _myPath.size()) _myList.setSelectedIndex(curSel);

    // update the list
    _myPlotter.update();
  }
    void move(int direction) {
      int index = -1;
      int size = 0;

      if (myCombo != null) {
        index = myCombo.getSelectedIndex();
        size = myCombo.getModel().getSize();
      } else if (myList != null) {
        index = myList.getSelectedIndex();
        size = myList.getModel().getSize();
      }

      if (index == -1 || size == 0) return;

      index += direction;

      if (index == size) {
        if (!UISettings.getInstance().CYCLE_SCROLLING) return;
        index = 0;
      } else if (index == -1) {
        if (!UISettings.getInstance().CYCLE_SCROLLING) return;
        index = size - 1;
      }

      if (myCombo != null) {
        myCombo.setSelectedIndex(index);
      } else if (myList != null) {
        myList.setSelectedIndex(index);
      }
    }
Esempio n. 27
0
 public final void setCode(String code) {
   int idx = filteredData.indexOf(code);
   if (idx != -1) {
     selectionList.setSelectedIndex(idx);
     selectionList.ensureIndexIsVisible(idx);
   }
 }
Esempio n. 28
0
  public SplitPaneDemo() {

    // Create the list of images and put it in a scroll pane.

    list = new JList(imageNames);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    list.addListSelectionListener(this);

    JScrollPane listScrollPane = new JScrollPane(list);
    picture = new JLabel();
    picture.setFont(picture.getFont().deriveFont(Font.ITALIC));
    picture.setHorizontalAlignment(JLabel.CENTER);

    JScrollPane pictureScrollPane = new JScrollPane(picture);

    // Create a split pane with the two scroll panes in it.
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane, pictureScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(150);

    // Provide minimum sizes for the two components in the split pane.
    Dimension minimumSize = new Dimension(100, 50);
    listScrollPane.setMinimumSize(minimumSize);
    pictureScrollPane.setMinimumSize(minimumSize);

    // Provide a preferred size for the split pane.
    splitPane.setPreferredSize(new Dimension(400, 200));
    updateLabel(imageNames[list.getSelectedIndex()]);
  }
Esempio n. 29
0
  /** Updates the test chooser with possible tests */
  protected void setTTester() {

    String name = (new SimpleDateFormat("HH:mm:ss - ")).format(new Date()) + "Available resultsets";
    StringBuffer outBuff = new StringBuffer();
    outBuff.append("Available resultsets\n" + m_TTester.resultsetKey() + "\n\n");
    m_History.addResult(name, outBuff);
    m_History.setSingle(name);

    m_TestsModel.removeAllElements();
    for (int i = 0; i < m_TTester.getNumResultsets(); i++) {
      String tname = m_TTester.getResultsetName(i);
      /*      if (tname.length() > 20) {
      tname = tname.substring(0, 20);
      } */
      m_TestsModel.addElement(tname);
    }
    m_TestsModel.addElement("Summary");
    m_TestsModel.addElement("Ranking");
    // ================ BEGIN EDIT melville ================
    m_TestsModel.addElement("Learning Curve Summary");
    // ================ END EDIT melville ================
    m_TestsList.setSelectedIndex(0);
    m_TestsButton.setEnabled(true);

    m_PerformBut.setEnabled(true);
  }
  /**
   * @param owner the parent Window (Dialog or Frame)
   * @param frame the JabRef Frame
   * @param panel the currently selected BasePanel
   * @param modal should this dialog be modal?
   * @param metaData The metadata of the current database
   * @param fieldName the field this selector is initialized for. May be null.
   */
  public ContentSelectorDialog2(
      Window owner,
      JabRefFrame frame,
      BasePanel panel,
      boolean modal,
      MetaData metaData,
      String fieldName) {
    super(owner, Globals.lang("Setup selectors"));
    this.setModal(modal);
    this.metaData = metaData;
    this.frame = frame;
    this.panel = panel;
    this.currentField = fieldName;

    // help = new JButton(Globals.lang("Help"));
    // help.addActionListener(new HelpAction(frame.helpDiag, GUIGlobals.contentSelectorHelp,
    // "Help"));
    // help = new HelpAction(frame.helpDiag, GUIGlobals.contentSelectorHelp, "Help");
    initLayout();
    //  wordSelector.addItem(WORD_EMPTY_TEXT);

    setupFieldSelector();
    setupWordSelector();
    setupActions();
    Util.bindCloseDialogKeyToCancelAction(this.rootPane, cancel.getAction());
    int fieldInd = fieldListModel.indexOf(currentField);
    if (fieldInd >= 0) fieldList.setSelectedIndex(fieldInd);

    pack();
  }