Example #1
0
  public void setBlock(int idx) {
    model.setBlock(idx);
    lines.setBlock(idx);
    lines.setRowCount(this.getRowCount());

    onTableChanged(true);
  }
Example #2
0
  public ContentView(final ContentPane control) {
    super(new GridLayout(1, 1));
    this.control = control;

    data = new JTable();
    data.setModel(model = new ContentModel(getControl().getQueryModel() == null));
    data.addMouseListener(popup = new ContentPopup(this));
    data.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent key) {
            if (key.getKeyCode() == KeyEvent.VK_DOWN || key.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
              if ((ContentView.this.data.getSelectedRow()
                      == ContentView.this.data.getRowCount() - 1)
                  && !control.areAllRowsFetched()) {
                int col = ContentView.this.data.getSelectedColumn();
                int row = ContentView.this.data.getRowCount() - 1;
                ContentView.this.data.scrollRectToVisible(
                    ContentView.this.data.getCellRect(row, col, true));
                ContentView.this.data.setRowSelectionInterval(row + 1, row + 1);
                ContentView.this.data.scrollRectToVisible(
                    ContentView.this.data.getCellRect(row + 1, col, true));
                key.consume();
              }
            }
          }
        });

    JScrollPane scroll = new JScrollPane(data);
    scroll.getViewport().setBackground(UIManager.getDefaults().getColor("Table.background"));
    add(scroll);
    jsb = scroll.getVerticalScrollBar();
    jsb.addAdjustmentListener(new ListenerScrollBar());

    data.setRowSelectionAllowed(false);
    data.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    data.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    data.setDefaultRenderer(Object.class, new InternalCellRenderer());
    data.getTableHeader().addMouseListener(popup);
    data.getTableHeader().setReorderingAllowed(false);

    lines = new LineNumberView();
    lines.addMouseListener(popup);
    lines.setSelectionModel(data.getSelectionModel());
    scroll.setRowHeaderView(lines);

    JLabel cUL = new JLabel("#", JLabel.CENTER);
    cUL.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    cUL.setFont(UIManager.getFont("TableHeader.font"));
    scroll.setCorner(JScrollPane.UPPER_LEFT_CORNER, cUL);

    JLabel cLL = new JLabel();
    cLL.setBorder(new CustomLineBorder(true, false, false, false));
    scroll.setCorner(JScrollPane.LOWER_LEFT_CORNER, cLL);

    data.getColumnModel().getSelectionModel().addListSelectionListener(this);

    data.getActionMap().put("copy", ((JMenuItem) popup.getSubElementsAt(1)).getAction());
    data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), "copy");

    data.getActionMap().put("paste", ((JMenuItem) popup.getSubElementsAt(2)).getAction());
    data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "paste");

    data.getActionMap().put("set-null", ((JMenuItem) popup.getSubElementsAt(3)).getAction());
    data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "set-null");

    MouseAdapter ma =
        new MouseAdapter() {
          public void mousePressed(MouseEvent me) {
            ContentView.this.data.setColumnSelectionAllowed(
                me.getSource() == ContentView.this.data.getTableHeader());
            ContentView.this.data.setRowSelectionAllowed(me.getSource() == ContentView.this.lines);
          }
        };

    data.getTableHeader().addMouseListener(ma);
    data.addMouseListener(ma);
    lines.addMouseListener(ma);
  }
Example #3
0
 public void onTableChanged(boolean onlyData) {
   data.tableChanged(onlyData ? new TableModelEvent(model) : null);
   lines.tableChanged(null);
 }
Example #4
0
 public void reset() {
   data.setModel(model = new ContentModel());
   lines.setRowCount(0);
   lines.setBlock(1);
 }
Example #5
0
 public Object getLineAt(int row) {
   return lines.getValueAt(row, 0);
 }
Example #6
0
  public void insertRow(int row) {
    model.insertRow(row);
    lines.setRowCount(this.getRowCount());

    onTableChanged(true);
  }
Example #7
0
 public void addRow(Object[] rowdata, boolean newrow) {
   model.addRow(rowdata, newrow);
   lines.setRowCount(this.getRowCount());
 }