📄 cellbrowser.java
字号:
List<Cell> cells = getSelectedCells(); for (Cell cell : cells) { WindowFrame wf = WindowFrame.getCurrentWindowFrame(); if (!newWindow && wf == null) newWindow = true; if (newWindow) { WindowFrame.createEditWindow(cell); } else { wf.setCellWindow(cell, null); } // if multiple cells selected, all cells after first // should be opened in new window newWindow = true; } closeDialog(null); // we have performed the action } else if (action == DoAction.deleteCell) { confirmDelete = confirmDeletions.isSelected(); List<Cell> cells = getSelectedCells(); Set<String> deletedCells = new HashSet<String>(); for(Cell cell : cells) { // make sure the user really wants to delete the cell if (confirmDelete) { int response = JOptionPane.showConfirmDialog(TopLevel.getCurrentJFrame(), "Are you sure you want to delete " + cell + "?", "Confirm Cell Deletion", JOptionPane.YES_NO_OPTION); if (response != JOptionPane.YES_OPTION) return; } // delete references to cell CircuitChanges.cleanCellRef(cell); deletedCells.add(cell.noLibDescribe()); } // delete all requested cells new CellChangeJobs.DeleteManyCells(cells); // pick a new selected cell lastSelectedCell = null; for (int i=cellListNames.size()-2; i>=0; i--) { String name = cellListNames.get(i); String nextName = cellListNames.get(i+1); if (deletedCells.contains(name) && !deletedCells.contains(nextName)) { lastSelectedCell = nextName; break; } } if (lastSelectedCell == null) { for (int i=0; i<cellListNames.size(); i++) { String name = cellListNames.get(i); if (!deletedCells.contains(name)) { lastSelectedCell = name; break; } } } updateCellList(); } else if (action == DoAction.renameCell) { Cell cell = getSelectedCell(); if (cell == null) return; String newName = newCellName.getText(); if (newName == null || newName.equals("")) return; CircuitChanges.renameCellInJob(cell, newName); lastSelectedCell = newName + cell.getView().getAbbreviationExtension(); //setCell(cell); } else if (action == DoAction.duplicateCell) { Cell cell = getSelectedCell(); if (cell == null) return; new CellMenu.NewCellName(false, cell); closeDialog(null); // we have performed the action updateCellList(); } else if (action == DoAction.selectCellToAssoc || action == DoAction.selectCellToCopy) { closeDialog(null); // we have performed the action } } // -------------------------------- Set State of Dialog ------------------------------ private void setLibrary(Library lib) { String libName = lib.getName(); libraryComboBox.setSelectedItem(libName); } private void setView(View view) { String viewName = view.getFullName(); viewComboBox.setSelectedItem(viewName); } private void setCell(Cell cell) { // clear filter cellFilter.setText(""); if (cell != null) { // this will make cell selected on update of list lastSelectedCell = cell.noLibDescribe(); Library lib = cell.getLibrary(); setLibrary(lib); View view = cell.getView(); setView(view); } updateCellList(); } // ---------------------------------- List ---------------------------------------- /** * Updates the Cell list depending on the library, view selected, and any filter in * the text box. */ private void updateCellList() { String libName = (String)libraryComboBox.getSelectedItem(); String viewName = (String)viewComboBox.getSelectedItem(); String filter = cellFilter.getText(); // get library if specified (all if not) Library lib = Library.findLibrary(libName); // get view if specified (all if not) View view = null; for (Iterator<View> it = View.getViews(); it.hasNext(); ) { View v = it.next(); if (v.getFullName().equals(viewName)) { view = v; break; } } // use cached (last) filter Pattern if no change Pattern pat; if (filter.equals("*")) filter = ""; if (filter.equals(lastFilter)) { pat = lastPattern; } else { try { pat = Pattern.compile(filter, Pattern.CASE_INSENSITIVE); } catch(java.util.regex.PatternSyntaxException e) { pat = null; filter = ""; } lastPattern = pat; lastFilter = filter; } cellList = new ArrayList<Cell>(); if (lib == null) { // do all libraries for (Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library library = it.next(); for (Iterator<Cell> it2 = library.getCells(); it2.hasNext(); ) { Cell c = it2.next(); if (view != null) { if (view != c.getView()) continue; // skip if not filtered view } if (pat != null) { Matcher mat = pat.matcher(c.noLibDescribe()); if (!mat.find()) continue; // skip if doesn't match filter } cellList.add(c); } } } else { // just do selected library for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell c = it.next(); if (view != null) { if (view != c.getView()) continue; // skip if not filtered view } if (!filter.equals("")) { Matcher mat = pat.matcher(c.noLibDescribe()); if (!mat.find()) continue; // skip if doesn't match filter } cellList.add(c); } } // sort appropriately if (sortNumerically.isSelected()) { // sort list by name, considering numbers Collections.sort(cellList); } else { // sort list by name, not considering numbers Collections.sort(cellList, new TextUtils.CellsByName()); } cellListNames = new ArrayList<String>(); for (Cell c : cellList) { cellListNames.add(c.noLibDescribe()); } jList1.setListData(cellListNames.toArray()); // if nothing selected or found, then disable the button doAction.setEnabled(cellListNames.size()>0); // update JScrollPane's scroll bars for new size list jList1.setVisibleRowCount(jList1.getModel().getSize()); jList1.setPreferredSize(jList1.getPreferredScrollableViewportSize()); jList1.revalidate(); // changing lists will have triggered update to cell list, go to last selected cell now if (lastSelectedCell != null) { int i; for (i=0; i<cellListNames.size(); i++) { String name = cellListNames.get(i); if (name.equals(lastSelectedCell)) { jList1.setSelectedIndex(i); break; } } if (i == cellListNames.size()) { lastSelectedCell = null; } } if (lastSelectedCell == null) { // didn't find anything, try to find current cell in the list Cell cell = WindowFrame.getCurrentCell(); if (cell != null) { String findname = cell.noLibDescribe(); for (int i=0; i<cellListNames.size(); i++) { String name = cellListNames.get(i); if (name.equals(findname)) { jList1.setSelectedIndex(i); lastSelectedCell = findname; break; } } } } } /** * Get selected Cell by user in Cell List * @return Cell or null if no cell is selected */ public Cell getSelectedCell() { if (cancelled) return null; int i = jList1.getSelectedIndex(); return (i == -1)? null : cellList.get(i); } /** * Get a list of selected Cells. * @return a list of selected Cells, or an empty list if none selected. */ private List<Cell> getSelectedCells() { int [] is = jList1.getSelectedIndices(); ArrayList<Cell> list = new ArrayList<Cell>(); for (int i=0; i<is.length; i++) { int celli = is[i]; Cell cell = cellList.get(celli); if (cell == null) continue; list.add(cell); } return list; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancel; private javax.swing.JTextField cellFilter; private javax.swing.JButton doAction; private javax.swing.JButton done; private javax.swing.JPanel extrasPanel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JList jList1; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSeparator jSeparator1; private javax.swing.JComboBox libraryComboBox; private javax.swing.JComboBox viewComboBox; // End of variables declaration//GEN-END:variables }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -