コード例 #1
0
 protected Transferable createTransferable(JComponent c) {
   JList lista = (JList) c;
   origem = c;
   Sistema[] sistemas = null;
   if (lista.getSelectedIndices() != null && lista.getSelectedIndices().length > 0) {
     sistemas = new Sistema[lista.getSelectedIndices().length];
     System.arraycopy(
         lista.getSelectedValues(), 0, sistemas, 0, lista.getSelectedIndices().length);
   }
   return new SistemaTransferable(sistemas);
 }
コード例 #2
0
ファイル: ResultsPanel.java プロジェクト: huangwen87/mdrill
  /** Swaps the keys for dataset and result. */
  protected void swapDatasetKeyAndResultKey() {
    int[] tmpSelected;
    Range tmpRange;

    // lists
    tmpSelected = m_DatasetKeyList.getSelectedIndices();
    m_DatasetKeyList.setSelectedIndices(m_ResultKeyList.getSelectedIndices());
    m_ResultKeyList.setSelectedIndices(tmpSelected);

    // tester
    tmpRange = m_TTester.getDatasetKeyColumns();
    m_TTester.setDatasetKeyColumns(m_TTester.getResultsetKeyColumns());
    m_TTester.setResultsetKeyColumns(tmpRange);
    setTTester();
  }
コード例 #3
0
  private boolean delimitSelection() {
    int indices[] = labels.getSelectedIndices();
    if (indices == null || indices.length == 0) return false;

    if (indices[0] == 0) tStart = 0;
    else {
      String prevLine = (String) labels.getModel().getElementAt(indices[0] - 1);
      StringTokenizer t = new StringTokenizer(prevLine);
      String startTime = t.nextToken();
      try {
        tStart = Double.parseDouble(startTime);
      } catch (NumberFormatException nfe) {
        tStart = 0;
      }
    }
    String lastLine = (String) labels.getModel().getElementAt(indices[indices.length - 1]);
    StringTokenizer t = new StringTokenizer(lastLine);
    String endTime = t.nextToken();
    try {
      tEnd = Double.parseDouble(endTime);
    } catch (NumberFormatException nfe) {
      return false;
    }
    return true;
  }
コード例 #4
0
 /**
  * Returns the selected elements in the selected list
  *
  * @return List
  */
 private List getSelectedChoices() {
   List result = new ArrayList();
   for (int index : selectedList.getSelectedIndices()) {
     result.add(selectedList.getModel().getElementAt(index));
   }
   return result;
 }
コード例 #5
0
    /*
     * Handles the checkbox selection process. Uses the bounds property of the
     * check box within the selected cell to determine whether the checkbox should
     * be selected or not
     **/
    public void mouseReleased(MouseEvent e) {
      if (list == null
          || list.getSelectedIndex() == -1
          || !isEnabled(list.locationToIndex(e.getPoint()))) {
        return;
      }

      int[] indices = list.getSelectedIndices();

      // get the current relative position of the check box
      // rect = box.getBounds(rect);

      for (int i = 0; i < indices.length; i++) {

        // get the current relative position of the check box
        int loc = list.locationToIndex(e.getPoint());
        rect = list.getCellBounds(loc, loc);

        // ensure the point clicked in within the checkBox
        /*if(e.getX() < (rect.getX() + 20) ) {
        	selState[indices[i]] = !selState[indices[i]];
        	setSelStateList(selState);
        } */
      }

      list.revalidate();
      list.repaint();
    }
コード例 #6
0
  // Listener method for list selection changes.
  public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting() == false) {

      if (list.getSelectedIndex() == -1) {
        // No selection: disable delete, up, and down buttons.
        deleteButton.setEnabled(false);
        upButton.setEnabled(false);
        downButton.setEnabled(false);
        nameField.setText("");

      } else if (list.getSelectedIndices().length > 1) {
        // Multiple selection: disable up and down buttons.
        deleteButton.setEnabled(true);
        upButton.setEnabled(false);
        downButton.setEnabled(false);

      } else {
        // Single selection: permit all operations.
        deleteButton.setEnabled(true);
        upButton.setEnabled(true);
        downButton.setEnabled(true);
        nameField.setText(list.getSelectedValue().toString());
      }
    }
  }
コード例 #7
0
ファイル: ResultsPanel.java プロジェクト: huangwen87/mdrill
  public void setDatasetKeyFromDialog() {

    ListSelectorDialog jd = new ListSelectorDialog(null, m_DatasetKeyList);

    // Open the dialog
    int result = jd.showDialog();

    // If accepted, update the ttester
    if (result == ListSelectorDialog.APPROVE_OPTION) {
      int[] selected = m_DatasetKeyList.getSelectedIndices();
      String selectedList = "";
      for (int i = 0; i < selected.length; i++) {
        selectedList += "," + (selected[i] + 1);
      }
      Range generatorRange = new Range();
      if (selectedList.length() != 0) {
        try {
          generatorRange.setRanges(selectedList);
        } catch (Exception ex) {
          ex.printStackTrace();
          System.err.println(ex.getMessage());
        }
      }
      m_TTester.setDatasetKeyColumns(generatorRange);
      setTTester();
    }
  }
コード例 #8
0
 void enableButtons(JList list) {
   int nSelected = list.getSelectedIndices().length;
   int nListed = list.getModel().getSize();
   saveButton.setEnabled(nListed > 0);
   deleteInstanceButton.setEnabled(nSelected > 0);
   showInstanceButton.setEnabled(nSelected == 1);
 }
コード例 #9
0
 public void valueChanged(ListSelectionEvent e) { // 事件处理
   int temp[] = list1.getSelectedIndices();
   System.out.print("选定的内容:");
   for (int i = 0; i < temp.length; i++) {
     System.out.print(list1.getModel().getElementAt(i) + "、");
   }
   System.out.println();
 }
コード例 #10
0
ファイル: MapDialogs.java プロジェクト: Tiim/Illarion-Java
  public static Map[] showOpenMapDialog(final JFrame owner) throws IOException {
    final JFileChooser ch = new JFileChooser();
    if (config.getFile("mapLastOpenDir") != null) {
      ch.setCurrentDirectory(config.getFile("mapLastOpenDir"));
    }
    ch.setDialogType(JFileChooser.OPEN_DIALOG);
    ch.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (ch.showOpenDialog(MainFrame.getInstance()) != JFileChooser.APPROVE_OPTION) {
      return null;
    }
    final File dir = ch.getSelectedFile();
    config.set("mapLastOpenDir", dir);
    final String[] maps = dir.list(FILTER_TILES);
    for (int i = 0; i < maps.length; ++i) {
      maps[i] = maps[i].substring(0, maps[i].length() - MapIO.EXT_TILE.length());
    }
    final JDialog dialog = new JDialog(owner, Lang.getMsg("gui.chooser"));
    dialog.setModal(true);
    dialog.setLocationRelativeTo(null);
    dialog.setLayout(new BorderLayout());

    final JList list = new JList(maps);
    final JButton btn = new JButton(Lang.getMsg("gui.chooser.Ok"));

    btn.addActionListener(
        new AbstractAction() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            if (list.getSelectedValue() != null) {
              dialog.setVisible(false);
            }
          }
        });

    dialog.add(new JScrollPane(list), BorderLayout.CENTER);
    dialog.add(btn, BorderLayout.SOUTH);
    dialog.pack();
    dialog.setVisible(true);
    dialog.dispose();

    Map[] loadedMaps = new Map[list.getSelectedIndices().length];
    for (int i = 0; i < list.getSelectedIndices().length; i++) {
      loadedMaps[i] = MapIO.loadMap(dir.getPath(), (String) list.getSelectedValues()[i]);
    }
    return loadedMaps;
  }
コード例 #11
0
 public void actionPerformed(java.awt.event.ActionEvent evt) {
   String command = evt.getActionCommand();
   if (command.equals(CommandButtons.okCommand)) {
     selectedIndices = list.getSelectedIndices();
     System.out.println("Selected indices has length " + selectedIndices.length);
   } else if (command.equals(CommandButtons.cancelCommand)) ;
   close();
 }
コード例 #12
0
ファイル: LegendUIChooser.java プロジェクト: jparty/orbisgis
  public Object[] getSelectedElements() {
    ArrayList<Object> ret = new ArrayList<Object>();
    int[] indexes = lst.getSelectedIndices();
    for (int index : indexes) {
      ret.add(ids[index]);
    }

    return ret.toArray();
  }
コード例 #13
0
ファイル: JList_class.java プロジェクト: yung6699/Java
 @Override
 public void valueChanged(ListSelectionEvent e) {
   // TODO Auto-generated method stub
   int[] indices = jlst.getSelectedIndices();
   System.out.println(indices.length);
   for (int i = 0; i < indices.length; i++) {
     textarea.append(title[indices[i]] + "\n");
   }
 }
 public void actionPerformed(ActionEvent e) {
   DefaultListModel listModel = null;
   JList list = null;
   if (((JButton) e.getSource()).getName().equals(REMOVE_SELECTED)) {
     list = failedPlatesList;
     listModel = (DefaultListModel) failedPlatesList.getModel();
   } else {
     list = destinationsList;
     listModel = (DefaultListModel) destinationsList.getModel();
   }
   if (list.getSelectedIndices().length > 0) {
     int[] temp = list.getSelectedIndices();
     int[] selectedIndices = list.getSelectedIndices();
     for (int i = temp.length - 1; i >= 0; i--) {
       selectedIndices = list.getSelectedIndices();
       listModel.removeElementAt(selectedIndices[i]);
     }
   }
 }
コード例 #15
0
ファイル: JList7.java プロジェクト: kelindev/javaStudy
 public void valueChanged(ListSelectionEvent e) {
   int tmp = 0;
   String stmp = "您目前选取:";
   int[] index = list.getSelectedIndices();
   for (int i = 0; i < index.length; i++) {
     tmp = index[i];
     stmp = stmp + s[tmp] + "  ";
   }
   label.setText(stmp);
 }
コード例 #16
0
 /** {@inheritDoc} */
 @Override
 protected Transferable createTransferable(JComponent c) {
   JList list = (JList) c;
   DefaultListModel model = (DefaultListModel) list.getModel();
   List<TradeRouteStop> stops = new ArrayList<>();
   for (int index : list.getSelectedIndices()) {
     stops.add((TradeRouteStop) model.get(index));
   }
   return new StopListTransferable(stops);
 }
コード例 #17
0
ファイル: BuildQueuePanel.java プロジェクト: nav18/freecool
 /**
  * Returns a <code>Transferable</code> suitable for wrapping the build queue.
  *
  * @param comp The source of the build queue.
  * @return A Transferable suitable for wrapping the build queue.
  */
 @Override
 @SuppressWarnings("deprecation") // FIXME in Java7
 protected Transferable createTransferable(JComponent comp) {
   if (comp instanceof JList) {
     source = (JList) comp;
     indices = source.getSelectedIndices();
     List<BuildableType> buildQueue = getBuildableTypes(source.getSelectedValues());
     return new BuildQueueTransferable(buildQueue);
   } else {
     return null;
   }
 }
コード例 #18
0
 private void moveOne(
     IndividualListSelectionModel sourceModel,
     IndividualListSelectionModel targetModel,
     JList source) {
   int[] indices = source.getSelectedIndices();
   if (indices.length == 0) return;
   for (int i = indices.length - 1; i >= 0; i--) {
     Object object = sourceModel.getObjectAt(indices[i]);
     sourceModel.remove(indices[i]);
     targetModel.add(object, targetModel.getSize());
   }
 }
コード例 #19
0
ファイル: FileChooserPanel.java プロジェクト: byanto/knip
  /*
   * when the remove button was pressed
   */
  private void onRemove() {
    if (m_selectedFileListModel.getSize() == 0) {

      JOptionPane.showMessageDialog(
          this, "No files in list to Remove", "Error", JOptionPane.ERROR_MESSAGE);

      return;
    }
    m_selectedFileListModel.remove(m_selectedFileList.getSelectedIndices());
    m_selectedFileList.clearSelection();
    fireSelectionChangedEvent();
  }
コード例 #20
0
  @Override
  public void validate() throws InvalidSettingsException {

    final int[] selection = m_lFilter.getSelectedIndices();
    final String[] selName = new String[selection.length];

    for (int i = 0; i < selection.length; i++) {
      selName[i] = m_filter.getVariantNames()[selection[i]];
    }

    m_setting = new ConstantFilterSetting(m_filter, selName);
  }
コード例 #21
0
  public void actionPerformed(final AnActionEvent event) {
    final ListSelectionModel selectionModel = list.getSelectionModel();
    if (!selectionModel.isSelectionEmpty()) {
      // shift the indices
      final int[] selectedIndices = list.getSelectedIndices();
      listModel.shiftElements(selectedIndices, true);

      // now update the list selection
      for (int i = 0; i < selectedIndices.length; i++) {
        selectedIndices[i] = selectedIndices[i] + 1;
      }
      list.setSelectedIndices(selectedIndices);
      list.ensureIndexIsVisible(selectedIndices[selectedIndices.length - 1]);
    }
  }
コード例 #22
0
  private void adjustFilter() {
    int conjunctionMode = conjunctionBox.getSelectedIndex();
    Item[] searchFilter = null;
    int[] selectedIndices = conclusionList.getSelectedIndices();
    if ((selectedIndices.length > 0) && (selectedIndices.length <= itemArray.length)) {
      searchFilter = new Item[selectedIndices.length];
      int counter = 0;
      for (int s : selectedIndices) {
        searchFilter[counter++] = itemArray[s];
      }
    }

    double minRatio = criterionMinSlider.getValue() / (double) MAX_VALUE;
    fireFilteringEvent(searchFilter, conjunctionMode, minRatio);
  }
コード例 #23
0
  public void keyPressed(KeyEvent e) {
    boolean undoNeeded = false;

    switch (e.getKeyCode()) {
      case KeyEvent.VK_DELETE:
      case KeyEvent.VK_BACK_SPACE:
        int[] selRows = rowHeader.getSelectedIndices();
        undoNeeded = table.getCASView().deleteCasCells(selRows);
        break;
    }

    if (undoNeeded) {
      // store undo info
      table.getApplication().storeUndoInfo();
    }
  }
コード例 #24
0
  @NotNull
  public static <T extends PsiElement> JBPopup getPsiElementPopup(
      @NotNull T[] elements,
      @NotNull final PsiElementListCellRenderer<T> renderer,
      @Nullable final String title,
      @NotNull final PsiElementProcessor<T> processor,
      @Nullable final T selection) {
    final JList list =
        new JBListWithHintProvider(elements) {
          @Nullable
          @Override
          protected PsiElement getPsiElementForHint(Object selectedValue) {
            return (PsiElement) selectedValue;
          }
        };
    list.setCellRenderer(renderer);

    list.setFont(EditorUtil.getEditorFont());

    if (selection != null) {
      list.setSelectedValue(selection, true);
    }

    final Runnable runnable =
        () -> {
          int[] ids = list.getSelectedIndices();
          if (ids == null || ids.length == 0) return;
          for (Object element : list.getSelectedValues()) {
            if (element != null) {
              processor.execute((T) element);
            }
          }
        };

    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    if (title != null) {
      builder.setTitle(title);
    }
    renderer.installSpeedSearch(builder, true);

    JBPopup popup = builder.setItemChoosenCallback(runnable).createPopup();

    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);

    return popup;
  }
コード例 #25
0
  private void removeButtonActionPerformed() {
    JList selectedList = getSelectedRobotsList();
    SelectedRobotsModel selectedModel = (SelectedRobotsModel) selectedList.getModel();
    int sel[] = selectedList.getSelectedIndices();

    for (int i = 0; i < sel.length; i++) {
      selectedRobots.remove(sel[i] - i);
    }
    selectedList.clearSelection();
    selectedModel.changed();
    fireStateChanged();
    if (selectedModel.getSize() < minRobots || selectedModel.getSize() > maxRobots) {
      showWrongNumInstructions();
    } else {
      showInstructions();
    }
  }
コード例 #26
0
ファイル: SplatPlotTable.java プロジェクト: jbudynk/starjava
 /** Update the view for changes in the selected spectra. */
 protected void update(ListSelectionEvent e) {
   if (!e.getValueIsAdjusting()) {
     int size = list.getModel().getSize();
     if (size > 0) {
       int[] indices = list.getSelectedIndices();
       if (indices.length > 0 && indices[0] > -1) {
         tableModel.setSpectraSelectedIndices(indices);
       } else {
         //  No selection.
         tableModel.setSpectraSelectedIndices(null);
       }
     } else {
       //  No spectra.
       tableModel.setSpectraSelectedIndices(null);
     }
   }
 }
コード例 #27
0
ファイル: CorpusEditor.java プロジェクト: kzn/gate
 public void actionPerformed(ActionEvent e) {
   List<Resource> loadedDocuments;
   try {
     // get all the documents loaded in the system
     loadedDocuments = Gate.getCreoleRegister().getAllInstances("gate.Document");
   } catch (GateException ge) {
     // gate.Document is not registered in creole.xml....what is!?
     throw new GateRuntimeException(
         "gate.Document is not registered in the creole register!\n"
             + "Something must be terribly wrong...take a vacation!");
   }
   Vector<String> docNames = new Vector<String>();
   for (Resource loadedDocument : new ArrayList<Resource>(loadedDocuments)) {
     if (corpus.contains(loadedDocument)) {
       loadedDocuments.remove(loadedDocument);
     } else {
       docNames.add(loadedDocument.getName());
     }
   }
   JList docList = new JList(docNames);
   docList.getSelectionModel().setSelectionInterval(0, docNames.size() - 1);
   docList.setCellRenderer(renderer);
   final JOptionPane optionPane =
       new JOptionPane(
           new JScrollPane(docList), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog =
       optionPane.createDialog(CorpusEditor.this, "Add document(s) to this corpus");
   docList.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (e.getClickCount() == 2) {
             optionPane.setValue(JOptionPane.OK_OPTION);
             dialog.dispose();
           }
         }
       });
   dialog.setVisible(true);
   if (optionPane.getValue().equals(JOptionPane.OK_OPTION)) {
     int[] selectedIndices = docList.getSelectedIndices();
     for (int selectedIndice : selectedIndices) {
       corpus.add((Document) loadedDocuments.get(selectedIndice));
     }
   }
   changeMessage();
 }
コード例 #28
0
 /** User made a selection. */
 @Override
 public boolean okPressed() {
   int[] index = configList.getSelectedIndices();
   if ((index == null) || (index.length == 0)) {
     if (delete) {
       configFilePath = null;
     } else {
       configFilePath = new String[] {landscapePath};
     }
   } else {
     configFilePath = new String[index.length];
     for (int i = 0; i < index.length; ++i) {
       configFilePath[i] = fileList[index[i]];
     }
   }
   setLastPath(fileChooser.getCurrentDirectory().getAbsolutePath());
   return (configFilePath != null);
 }
コード例 #29
0
ファイル: ResultsPanel.java プロジェクト: huangwen87/mdrill
  /** Carries out a t-test using the current configuration. */
  protected void performTest() {

    String sigStr = m_SigTex.getText();
    if (sigStr.length() != 0) {
      m_TTester.setSignificanceLevel((new Double(sigStr)).doubleValue());
    } else {
      m_TTester.setSignificanceLevel(ExperimenterDefaults.getSignificance());
    }

    // Carry out the test chosen and biff the results to the output area
    m_TTester.setShowStdDevs(m_ShowStdDevs.isSelected());
    if (m_Instances.attribute(m_SortCombo.getSelectedItem().toString()) != null)
      m_TTester.setSortColumn(
          m_Instances.attribute(m_SortCombo.getSelectedItem().toString()).index());
    else m_TTester.setSortColumn(-1);
    int compareCol = m_CompareCombo.getSelectedIndex();
    int tType = m_TestsList.getSelectedIndex();

    String name =
        (new SimpleDateFormat("HH:mm:ss - ")).format(new Date())
            + (String) m_CompareCombo.getSelectedItem()
            + " - "
            + (String) m_TestsList.getSelectedValue();
    StringBuffer outBuff = new StringBuffer();
    outBuff.append(m_TTester.header(compareCol));
    outBuff.append("\n");
    m_History.addResult(name, outBuff);
    m_History.setSingle(name);
    m_TTester.setDisplayedResultsets(m_DisplayedList.getSelectedIndices());
    m_TTester.setResultMatrix(m_ResultMatrix);
    try {
      if (tType < m_TTester.getNumResultsets()) {
        outBuff.append(m_TTester.multiResultsetFull(tType, compareCol));
      } else if (tType == m_TTester.getNumResultsets()) {
        outBuff.append(m_TTester.multiResultsetSummary(compareCol));
      } else {
        outBuff.append(m_TTester.multiResultsetRanking(compareCol));
      }
      outBuff.append("\n");
    } catch (Exception ex) {
      outBuff.append(ex.getMessage() + "\n");
    }
    m_History.updateResult(name);
  }
コード例 #30
0
 protected Transferable createTransferable(JComponent c) {
   if (c instanceof JList) {
     source = (JList) c;
     indices = source.getSelectedIndices();
     Object[] values = source.getSelectedValues();
     if (values == null || values.length == 0) {
       return null;
     }
     ArrayList alist = new ArrayList(values.length);
     for (int i = 0; i < values.length; i++) {
       Object o = values[i];
       String str = o.toString();
       if (str == null) str = "";
       alist.add(str);
     }
     return new ArrayListTransferable(alist);
   }
   return null;
 }