/** * Sets the table which is displayed in this panel. * * @param tcModel table to display */ private void setDisplayedTable(TopcatModel tcModel) { if (tcModel_ != null) { tcModel_.removeTopcatListener(tcListener_); tcModel_.getColumnModel().removeColumnModelListener(colListener_); } tcModel_ = tcModel; if (saveChooser_ != null) { saveChooser_.setEnabled(tcModel != null); } updateNameField(tcModel); updateSubsetField(tcModel); updateOrderField(tcModel); updateColsField(tcModel); updateRowsField(tcModel); if (tcModel != null) { tcModel.addTopcatListener(tcListener_); tcModel.getColumnModel().addColumnModelListener(colListener_); } }
/** * Constructor. * * @param sto output marshaller */ public CurrentSavePanel(StarTableOutput sto) { super("Current Table", TableSaveChooser.makeFormatBoxModel(sto, false)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); final JList tablesList = ControlWindow.getInstance().getTablesList(); /* Ensure displayed table is always the TOPCAT current table. */ tablesList.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { setDisplayedTable((TopcatModel) tablesList.getSelectedValue()); } }); /* Ensure that current table characteristics are always up to date. */ tcListener_ = new TopcatListener() { public void modelChanged(TopcatEvent evt) { TopcatModel tcModel = evt.getModel(); assert tcModel == tcModel_; int code = evt.getCode(); if (code == TopcatEvent.LABEL) { updateNameField(tcModel); } else if (code == TopcatEvent.CURRENT_SUBSET) { updateRowsField(tcModel); updateSubsetField(tcModel); } else if (code == TopcatEvent.CURRENT_ORDER) { updateOrderField(tcModel); } } }; colListener_ = new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent evt) { updateColsField(tcModel_); } public void columnRemoved(TableColumnModelEvent evt) { updateColsField(tcModel_); } public void columnMoved(TableColumnModelEvent evt) {} public void columnMarginChanged(ChangeEvent evt) {} public void columnSelectionChanged(ListSelectionEvent evt) {} }; /* Place components. */ setLayout(new BorderLayout()); LabelledComponentStack stack = new LabelledComponentStack(); Font inputFont = stack.getInputFont(); add(stack, BorderLayout.NORTH); nameField_ = new JLabel(); subsetField_ = new JLabel(); orderField_ = new JLabel(); colsField_ = new JLabel(); rowsField_ = new JLabel(); nameField_.setFont(inputFont); subsetField_.setFont(inputFont); orderField_.setFont(inputFont); colsField_.setFont(inputFont); rowsField_.setFont(inputFont); stack.addLine("Table", nameField_); stack.addLine("Current Subset", subsetField_); stack.addLine("Sort Order", orderField_); /* I thought this might be a good idea, but probably it's too much * information. */ if (false) { stack.addLine("Columns", colsField_); stack.addLine("Rows", rowsField_); } setDisplayedTable((TopcatModel) tablesList.getSelectedValue()); }
public void setActiveChooser(TableSaveChooser chooser) { saveChooser_ = chooser; if (saveChooser_ != null) { saveChooser_.setEnabled(tcModel_ != null); } }