示例#1
0
  /** Make pick table, DND enabled */
  public JTable makePickTable() {
    this.init();
    try { // following might fail due to a missing method on Mac Classic
      _sorter = new TableSorter(this);
      _table = jmri.util.JTableUtil.sortableDataModel(_sorter);
      _sorter.setTableHeader(_table.getTableHeader());
      _sorter.setColumnComparator(String.class, new jmri.util.SystemNameComparator());
      _table.setModel(_sorter);
    } catch (Throwable e) { // NoSuchMethodError, NoClassDefFoundError and others on early JVMs
      log.error("makePickTable: Unexpected error: " + e);
      _table = new JTable(this);
    }

    _table.setRowSelectionAllowed(true);
    _table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _table.setPreferredScrollableViewportSize(
        new java.awt.Dimension(250, _table.getRowHeight() * 7));
    _table.setDragEnabled(true);
    _table.setTransferHandler(new jmri.util.DnDTableExportHandler());

    _table.getTableHeader().setReorderingAllowed(true);
    _table.setColumnModel(new XTableColumnModel());
    _table.createDefaultColumnsFromModel();
    TableColumnModel columnModel = _table.getColumnModel();

    TableColumn sNameColumnT = columnModel.getColumn(SNAME_COLUMN);
    sNameColumnT.setResizable(true);
    sNameColumnT.setMinWidth(50);
    // sNameColumnT.setMaxWidth(200);

    TableColumn uNameColumnT = columnModel.getColumn(UNAME_COLUMN);
    uNameColumnT.setResizable(true);
    uNameColumnT.setMinWidth(100);
    // uNameColumnT.setMaxWidth(300);

    addMouseListenerToHeader(_table);

    return _table;
  }
示例#2
0
  public void initComponents() throws Exception {

    // set the frame's initial state
    setSize(500, 300);
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    tableModel = new TieTableModel();
    table = jmri.util.JTableUtil.sortableDataModel(tableModel);
    table.setRowSelectionAllowed(true);
    table.setPreferredScrollableViewportSize(new java.awt.Dimension(300, 350));

    TableColumnModel columnModel = table.getColumnModel();
    TableColumn column;
    column = columnModel.getColumn(TieTableModel.USERNAME_COLUMN);
    column.setMinWidth(20);
    // column.setMaxWidth(40);
    column.setResizable(true);
    column = columnModel.getColumn(TieTableModel.ID_COLUMN);
    column.setMinWidth(40);
    // column.setMaxWidth(85);
    column.setResizable(true);
    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
  }
示例#3
0
  /** Constructor method */
  public PollTablePane(jmri.ModifiedFlag flag) {
    super();

    this.modifiedFlag = flag;

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    pollModel = new PollDataModel(modifiedFlag);

    JTable pollTable = jmri.util.JTableUtil.sortableDataModel(pollModel);

    // install a button renderer & editor
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    pollTable.setDefaultRenderer(JButton.class, buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    pollTable.setDefaultEditor(JButton.class, buttonEditor);
    pollTable.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
    pollTable.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());

    try {
      jmri.util.com.sun.TableSorter tmodel = ((jmri.util.com.sun.TableSorter) pollTable.getModel());
      tmodel.setSortingStatus(PollDataModel.ADDRCOL, jmri.util.com.sun.TableSorter.ASCENDING);
    } catch (ClassCastException e3) {
    } // if not a sortable table model
    pollTable.setRowSelectionAllowed(false);
    pollTable.setPreferredScrollableViewportSize(new java.awt.Dimension(580, 80));

    JScrollPane scrollPane = new JScrollPane(pollTable);
    add(scrollPane);

    // status info on bottom
    JPanel p =
        new JPanel() {
          /** */
          private static final long serialVersionUID = 2303477665465877882L;

          public Dimension getMaximumSize() {
            int height = getPreferredSize().height;
            int width = super.getMaximumSize().width;
            return new Dimension(width, height);
          }
        };
    p.setLayout(new FlowLayout());

    polling = new JCheckBox(rb.getString("LabelPoll"));
    polling.setSelected(Engine.instance().getPolling());
    p.add(polling);
    polling.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            checkPolling();
          }
        });

    JPanel m = new JPanel();
    m.setLayout(new BoxLayout(m, BoxLayout.Y_AXIS));
    ButtonGroup g = new ButtonGroup();
    bscMode = new JRadioButton(rb.getString("LabelBscMode"));
    bscMode.setSelected(Engine.instance().getBscPollMode());
    m.add(bscMode);
    g.add(bscMode);
    bscMode.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            checkMode();
          }
        });
    directMode = new JRadioButton(rb.getString("LabelDirectMode"));
    directMode.setSelected(Engine.instance().getDirectPollMode());
    m.add(directMode);
    g.add(directMode);
    directMode.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            checkMode();
          }
        });
    throttleMode = new JRadioButton(rb.getString("LabelThrottleMode"));
    throttleMode.setSelected(Engine.instance().getThrottlePollMode());
    m.add(throttleMode);
    g.add(throttleMode);
    throttleMode.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            checkMode();
          }
        });
    p.add(m);

    p.add(Box.createHorizontalGlue());
    p.add(new JLabel(rb.getString("LabelDelay")));
    delay = new JTextField(5);
    delay.setText("" + Engine.instance().getPollingInterval());
    p.add(delay);
    delay.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            updateInterval();
          }
        });

    JButton b = new JButton(rb.getString("LabelSetDefault"));
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            setDefaults();
          }
        });
    p.add(b);

    add(p);
  }