private void initView() { AutomatonEditorPanel<T, S> panel = getEditorPanel(); T auto = panel.getAutomaton(); initTable(myAlg.getConvertedGrammar(), new UndoKeeper()); panel.setTool(createArrowTool(panel, auto)); MagnifiableScrollPane scroll = new MagnifiableScrollPane(myTable); scroll.setMinimumSize(myTable.getMinimumSize()); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel, scroll); Dimension size = getPreferredSize(), scrollSize = myTable.getMinimumSize(); double width = size.width + scrollSize.width; split.setPreferredSize(new Dimension((int) width, size.height)); double ratio = size.width / width; split.setDividerLocation(ratio); split.setResizeWeight(ratio); SizeSlider slider = new SizeSlider(scroll); JToolBar toolbar = initToolbar(); add(split, BorderLayout.CENTER); add(slider, BorderLayout.SOUTH); add(toolbar, BorderLayout.NORTH); slider.distributeMagnification(); size = new Dimension( (int) width, size.height + slider.getPreferredSize().height + toolbar.getPreferredSize().height); setPreferredSize(size); }
private void initTable(Grammar converted, UndoKeeper keeper) { final AutoProductionDataHelper helper = new AutoProductionDataHelper(converted, keeper); ProductionTableModel model = new ProductionTableModel(converted, keeper, helper) { public boolean isCellEditable(int row, int column) { return false; }; }; myTable = new ProductionTable(converted, keeper, true, model); myTable .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { changeSelection(); } }); converted .getProductionSet() .addListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (e instanceof AddEvent) { for (Object o : ((AddEvent) e).getToAdd()) { Production p = (Production) o; helper.add(getMaxRow(), new Object[] {p.getLHS(), null, p.getRHS()}); } } } }); }
private void changeSelection() { ListSelectionModel model = myTable.getSelectionModel(); AutomatonEditorPanel<T, S> panel = getEditorPanel(); panel.clearSelection(); int min = model.getMinSelectionIndex(), max = model.getMaxSelectionIndex(); if (min < 0) return; for (int i = min; i <= max; i++) if (model.isSelectedIndex(i) && myObjectMap.containsKey(i)) panel.selectObject(myObjectMap.get(i)); }
public int getMaxRow() { return myTable.getRowCount() - 1; }
private void clearSelection() { getEditorPanel().clearSelection(); myTable.clearSelection(); }
public void updateObjectMap(Object clicked, int row) { for (int i = row; i < myTable.getRowCount() - 1; i++) myObjectMap.put(i, clicked); myTable.setRowSelectionInterval(row, myTable.getRowCount() - 2); }