Search in sources :

Example 1 with TableColumnModelListener

use of javax.swing.event.TableColumnModelListener in project adempiere by adempiere.

the class WFActivity method jbInit.

//	dynInit
/**
	 * 	Static Init.
	 * 	Called after Dynamic Init
	 * 	@throws Exception
	 */
private void jbInit() throws Exception {
    int width = 150;
    centerPanel.setLayout(centerLayout);
    fNode.setReadWrite(false);
    fDescription.setReadWrite(false);
    fDescription.setPreferredSize(new Dimension(width, 40));
    fHelp.setReadWrite(false);
    fHelp.setPreferredSize(new Dimension(width, 40));
    fHistory.setReadWrite(false);
    fHistory.setPreferredSize(new Dimension(width, 80));
    fTextMsg.setPreferredSize(new Dimension(width, 40));
    //
    // bPrevious.addActionListener(this);
    // bNext.addActionListener(this);
    selTable.setModel(selTableModel);
    //  0-ID
    selTable.setColumnClass(0, IDColumn.class, false, " ");
    //  1-Priority
    selTable.setColumnClass(1, Integer.class, true);
    //  2-AD_WF_Node_ID
    selTable.setColumnClass(2, String.class, true);
    //  3-Summary
    selTable.setColumnClass(3, String.class, true);
    selTable.getSelectionModel().addListSelectionListener(this);
    // Listen the Column Move Event
    selTable.getColumnModel().addColumnModelListener(new TableColumnModelListener() {

        public void columnMoved(TableColumnModelEvent e) {
            if (columnValue == -1)
                columnValue = e.getFromIndex();
            columnNewValue = e.getToIndex();
        }

        @Override
        public void columnAdded(TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent e) {
        }

        @Override
        public void columnRemoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
        }
    });
    //Listen the mouse released Moved
    selTable.getTableHeader().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            if (columnValue != -1 && (columnValue == 0 || columnNewValue == 0))
                selTable.moveColumn(columnNewValue, columnValue);
            columnValue = -1;
            columnNewValue = -1;
        }
    });
    bZoom.addActionListener(this);
    bOK.addActionListener(this);
    //
    this.setLayout(new BorderLayout());
    this.add(centerPanel, BorderLayout.CENTER);
    this.add(statusBar, BorderLayout.SOUTH);
    //
    //	answers.setOpaque(false);
    answers.add(fAnswerText);
    answers.add(fAnswerList);
    answers.add(fAnswerButton);
    fAnswerButton.addActionListener(this);
    //
    int row = 0;
    selPane.setPreferredSize(new Dimension(width, 60));
    selPane.setMinimumSize(new Dimension(100, 60));
    centerPanel.add(selPane, new GridBagConstraints(0, row, 4, 1, 0.3, 0.3, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(5, 10, 5, 10), 0, 0));
    centerPanel.add(lNode, new GridBagConstraints(0, ++row, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(5, 10, 5, 5), 0, 0));
    centerPanel.add(fNode, new GridBagConstraints(1, row, 3, 2, 0.5, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 10), 0, 0));
    centerPanel.add(lDesctiption, new GridBagConstraints(0, ++row, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(5, 10, 5, 5), 0, 0));
    centerPanel.add(fDescription, new GridBagConstraints(1, row, 3, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 10), 0, 0));
    centerPanel.add(lHelp, new GridBagConstraints(0, ++row, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(2, 10, 5, 5), 0, 0));
    centerPanel.add(fHelp, new GridBagConstraints(1, row, 3, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 0, 5, 10), 0, 0));
    centerPanel.add(lHistory, new GridBagConstraints(0, ++row, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(5, 10, 5, 5), 0, 0));
    centerPanel.add(fHistory, new GridBagConstraints(1, row, 3, 1, 0.5, 0.5, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(5, 0, 5, 10), 0, 0));
    centerPanel.add(lAnswer, new GridBagConstraints(0, ++row, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 10, 5, 5), 0, 0));
    centerPanel.add(answers, new GridBagConstraints(1, row, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 0, 5, 5), 0, 0));
    centerPanel.add(bZoom, new GridBagConstraints(3, row, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 0, 10, 10), 0, 0));
    centerPanel.add(lTextMsg, new GridBagConstraints(0, ++row, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(5, 10, 5, 5), 0, 0));
    centerPanel.add(fTextMsg, new GridBagConstraints(1, row, 3, 1, 0.5, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 10), 0, 0));
    centerPanel.add(lForward, new GridBagConstraints(0, ++row, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 10, 5, 5), 0, 0));
    centerPanel.add(fForward, new GridBagConstraints(1, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 5, 0), 0, 0));
    centerPanel.add(lOptional, new GridBagConstraints(2, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
    centerPanel.add(bOK, new GridBagConstraints(3, row, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 10), 0, 0));
}
Also used : TableColumnModelEvent(javax.swing.event.TableColumnModelEvent) TableColumnModelListener(javax.swing.event.TableColumnModelListener) GridBagConstraints(java.awt.GridBagConstraints) MouseEvent(java.awt.event.MouseEvent) Insets(java.awt.Insets) ChangeEvent(javax.swing.event.ChangeEvent) BorderLayout(java.awt.BorderLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) Dimension(java.awt.Dimension)

Example 2 with TableColumnModelListener

use of javax.swing.event.TableColumnModelListener in project android by JetBrains.

the class ColumnTreeBuilder method build.

public JComponent build() {
    // Stash this value since it'll get stomped WideSelectionTreeUI.
    boolean showsRootHandles = myTree.getShowsRootHandles();
    myTree.setUI(new ColumnTreeUI());
    myTree.setShowsRootHandles(showsRootHandles);
    myTree.setCellRenderer(myCellRenderer);
    myTable.getColumnModel().addColumnModelListener(new TableColumnModelListener() {

        @Override
        public void columnAdded(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnRemoved(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent changeEvent) {
            myTree.revalidate();
            myTree.repaint();
        }

        @Override
        public void columnSelectionChanged(ListSelectionEvent listSelectionEvent) {
        }
    });
    myTable.setRowSorter(myRowSorter);
    myRowSorter.addRowSorterListener(event -> {
        if (myTreeSorter != null && !myRowSorter.getSortKeys().isEmpty()) {
            RowSorter.SortKey key = myRowSorter.getSortKeys().get(0);
            Comparator<?> comparator = myRowSorter.getComparator(key.getColumn());
            Enumeration<TreePath> expanded = myTree.getExpandedDescendants(new TreePath(myTree.getModel().getRoot()));
            comparator = key.getSortOrder() == SortOrder.ASCENDING ? comparator : Collections.reverseOrder(comparator);
            myTreeSorter.sort(comparator, key.getSortOrder());
            if (expanded != null) {
                while (expanded.hasMoreElements()) {
                    myTree.expandPath(expanded.nextElement());
                }
            }
        }
    });
    myTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    for (ColumnBuilder column : myColumnBuilders) {
        column.create(myTableModel);
    }
    for (int i = 0; i < myColumnBuilders.size(); i++) {
        ColumnBuilder column = myColumnBuilders.get(i);
        column.configure(i, myTable, myRowSorter, myCellRenderer);
    }
    JPanel panel = new TreeWrapperPanel(myTable, myTree);
    if (myBackground != null) {
        panel.setBackground(myBackground);
    }
    JTableHeader header = myTable.getTableHeader();
    header.setReorderingAllowed(false);
    JViewport viewport = new JViewport();
    viewport.setView(header);
    JBScrollPane scrollPane = new JBScrollPane(panel);
    scrollPane.setColumnHeader(viewport);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    return scrollPane;
}
Also used : TableColumnModelEvent(javax.swing.event.TableColumnModelEvent) TableColumnModelListener(javax.swing.event.TableColumnModelListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ChangeEvent(javax.swing.event.ChangeEvent) TreePath(javax.swing.tree.TreePath) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

ChangeEvent (javax.swing.event.ChangeEvent)2 ListSelectionEvent (javax.swing.event.ListSelectionEvent)2 TableColumnModelEvent (javax.swing.event.TableColumnModelEvent)2 TableColumnModelListener (javax.swing.event.TableColumnModelListener)2 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 Insets (java.awt.Insets)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 TreePath (javax.swing.tree.TreePath)1