List of usage examples for java.util Collections swap
private static void swap(Object[] arr, int i, int j)
From source file:com.nextep.designer.vcs.services.impl.VersioningService.java
@Override public void setCurrentActivity(IActivity currentActivity) { final int position = activities.indexOf(currentActivity); if (position > 0) { // Placing the current activity on top Collections.swap(activities, 0, position); } else if (position == -1) { // Updating the recent activity list activities.add(0, currentActivity); if (activities.size() > RECENT_ACTIVITIES_COUNT) { activities.remove(activities.size() - 1); }//from w w w.jav a 2 s .c om // Persisting recent activities final IEclipsePreferences prefs = new InstanceScope().getNode(VCSPlugin.PLUGIN_ID); for (int i = 0; i < Math.min(RECENT_ACTIVITIES_COUNT, activities.size()); i++) { prefs.put(VersioningPreferenceConstants.RECENT_ACTIVITIES_PREFIX + i, activities.get(i).getName()); } try { prefs.flush(); } catch (BackingStoreException e) { log.warn("Unable to save recent activities list: " + e.getMessage(), e); } } }
From source file:hydrograph.ui.parametergrid.dialog.MultiParameterFileDialog.java
private void moveRowUp(TableViewer parameterTableViewer) { Table table = parameterTableViewer.getTable(); int[] indexes = table.getSelectionIndices(); for (int index : indexes) { if (index > 0) { Collections.swap((List<Parameter>) parameters, index, index - 1); parameterTableViewer.refresh(); }/* ww w. jav a 2 s .c om*/ } }
From source file:hydrograph.ui.parametergrid.dialog.MultiParameterFileDialog.java
private void moveRowDown(TableViewer parameterTableViewer) { Table table = parameterTableViewer.getTable(); int[] indexes = table.getSelectionIndices(); for (int i = indexes.length - 1; i > -1; i--) { if (indexes[i] < parameters.size() - 1) { Collections.swap((List<Parameter>) parameters, indexes[i], indexes[i] + 1); parameterTableViewer.refresh(); }/*w ww . j a v a 2 s .c o m*/ } }
From source file:org.catrobat.catroid.ui.fragment.SoundFragment.java
private void moveSoundDown() { if (selectedSoundPosition != soundInfoList.size() - 1) { Collections.swap(soundInfoList, selectedSoundPosition + 1, selectedSoundPosition); adapter.notifyDataSetChanged();//from w w w.j a v a 2 s . c o m } }
From source file:org.catrobat.catroid.ui.fragment.SoundFragment.java
private void moveSoundToBottom() { for (int i = selectedSoundPosition; i < soundInfoList.size() - 1; i++) { Collections.swap(soundInfoList, i, i + 1); }/* ww w. j a va 2 s . c o m*/ adapter.notifyDataSetChanged(); }
From source file:org.catrobat.catroid.ui.fragment.SoundFragment.java
private void moveSoundUp() { if (selectedSoundPosition != 0) { Collections.swap(soundInfoList, selectedSoundPosition - 1, selectedSoundPosition); adapter.notifyDataSetChanged();/*from w w w .java 2 s. c om*/ } }
From source file:org.catrobat.catroid.ui.fragment.SoundFragment.java
private void moveSoundToTop() { for (int i = selectedSoundPosition; i > 0; i--) { Collections.swap(soundInfoList, i, i - 1); }/* w w w. j av a2 s. c om*/ adapter.notifyDataSetChanged(); }
From source file:lol.search.RankedStatsPage.java
private void sort() { int count = 0; int max = 0;/*ww w . j a v a2s .c om*/ int maxPosition = 0; for (int i = 0; i < objChampRankedList.size(); i++) { for (int j = count; j < objChampRankedList.size(); j++) { try { if (this.objChampRankedList.get(j).getJSONObject("stats").getInt("totalSessionsPlayed") > max) { max = this.objChampRankedList.get(j).getJSONObject("stats").getInt("totalSessionsPlayed"); maxPosition = j; } } catch (JSONException ex) { Logger.getLogger(RankedStatsPage.class.getName()).log(Level.SEVERE, null, ex); } } Collections.swap(objChampRankedList, maxPosition, i); max = 0; maxPosition = 0; count++; } /* for(int i = 0; i < objChampRankedList.size(); i++){ System.out.println(objChampRankedList.get(i)); } */ }
From source file:org.medcare.Dicom.DicomActivity.java
public int selectDicom(String arg) { Log.e(TAG, "TESTDICOM selectDicom !!!!!!!!! arg " + arg); String[] params = cutString(arg, ","); int index = -1; if (params.length >= 2) { index = Integer.parseInt(params[1]); } else {/*w ww .j av a 2s . co m*/ return -1; } Log.e(TAG, "TESTDICOM selectDicom !!!!!!!!!!! index " + index); //curentImageController = dicomView._graphics.get(index); Collections.swap(dicomView.imageControllers, dicomView.imageControllers.size() - 1, index); dicomView.setCurrentImageControllerIndex(index); curentImageController.setChange(true); return index; }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Change the order of the favorite rows. * //from ww w . j av a 2 s .c om * @param context */ public static void displayChangeRowOrder(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.row_list); final ListView listView = (ListView) dialog.findViewById(R.id.rowList); ArrayList<RowInfo> persistedRows = RowsTable.getRows(context); final ArrayList<RowInfo> rows = new ArrayList<RowInfo>(); // Add in reverse order to match favorite rows order for (RowInfo rowInfo : persistedRows) { rows.add(0, rowInfo); } final RowAdapter rowAdapter = new RowAdapter(context, rows); listView.setAdapter(rowAdapter); listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { RowInfo rowInfo = (RowInfo) parent.getAdapter().getItem(position); if (rowInfo.isSelected()) { rowInfo.setSelected(false); // Persist the new row order try { int counter = 0; for (int i = rowAdapter.getCount() - 1; i >= 0; i--) { RowInfo currentRowInfo = (RowInfo) parent.getAdapter().getItem(i); RowsTable.updateRow(context, currentRowInfo.getId(), currentRowInfo.getTitle(), counter, currentRowInfo.getType()); counter++; } } catch (Exception e) { Log.e(LOG_TAG, "displayChangeRowOrder", e); } Analytics.logEvent(Analytics.CHANGE_ROW_ORDER); } else { rowInfo.setSelected(true); } rowAdapter.notifyDataSetChanged(); } }); listView.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Swap the selected item in the list int selectedRowIndex = -1; for (int i = 0; i < rows.size(); i++) { RowInfo rowInfo = rows.get(i); if (rowInfo.isSelected()) { selectedRowIndex = i; break; } } if (selectedRowIndex != -1) { try { Collections.swap(rows, position, selectedRowIndex); rowAdapter.notifyDataSetChanged(); } catch (Exception e) { Log.e(LOG_TAG, "displayChangeRowOrder", e); } } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); listView.setDrawingCacheEnabled(true); listView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); context.reloadAllGalleries(); } }); Button okButton = (Button) dialog.findViewById(R.id.okButton); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { context.showCover(false); dialog.dismiss(); context.reloadAllGalleries(); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_CHANGE_ROW_ORDER); }