Java Code Examples for javax.swing.SortOrder

The following examples show how to use javax.swing.SortOrder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: visualvm   Source File: TreeTableView.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setSortColumn(DataType dataType, SortOrder sortOrder) {
    if (treeTable == null) {
        initialSortColumn = dataType;
        initialSortOrder = sortOrder;
    } else {
        int column = getColumn(dataType);
        if (column == -1) return;
        
        if (sortOrder == null) sortOrder = SortOrder.UNSORTED;
        
        List<? extends RowSorter.SortKey> sortKeys = treeTable.getRowSorter().getSortKeys();
        if (sortKeys != null && sortKeys.size() == 1) {
            RowSorter.SortKey sortKey = sortKeys.get(0);
            if (sortKey.getColumn() == column && sortOrder.equals(sortKey.getSortOrder())) return;
        }

        treeTable.setSorting(column, sortOrder);
    }
}
 
Example 2
Source Project: littleluck   Source File: LuckTableCellHeaderRenderer.java    License: Apache License 2.0 6 votes vote down vote up
public static SortOrder getColumnSortOrder(JTable table, int column)
{
    SortOrder rv = null;

    if (table == null || table.getRowSorter() == null)
    {
        return rv;
    }

    java.util.List<? extends RowSorter.SortKey> sortKeys = table
            .getRowSorter().getSortKeys();

    if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table
            .convertColumnIndexToModel(column))
    {
        rv = sortKeys.get(0).getSortOrder();
    }

    return rv;
}
 
Example 3
Source Project: visualvm   Source File: ProfilerRowSorter.java    License: GNU General Public License v2.0 6 votes vote down vote up
void loadFromStorage(Properties properties, ProfilerTable table) {
        String columnS = properties.getProperty(SORT_COLUMN_KEY);
        String orderS = properties.getProperty(SORT_ORDER_KEY);
        if (columnS != null) {
            try {
                int column = Integer.parseInt(columnS);
                SortOrder order = getSortOrder(orderS);
//                if (SortOrder.UNSORTED.equals(order)) order = getDefaultSortOrder(column);
                setSortColumn(column, order);
            } catch (NumberFormatException e) {
                // Reset sorting? Set default column?
            }
        } else {
            // Reset sorting? Set default column?
        }
    }
 
Example 4
Source Project: scelight   Source File: JavaSysPropsPage.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public JComponent createPageComp() {
	final BorderPanel p = new BorderPanel();
	
	final XTable table = new XTable();
	
	final Vector< Vector< Object > > data = new Vector<>();
	
	final Properties props = System.getProperties();
	// Use name enumeration which properly returns names from the default properties of a property
	// (while HashTable.entrySet() does not!).
	final Enumeration< ? > nameEnum = props.propertyNames();
	while ( nameEnum.hasMoreElements() ) {
		final Object name = nameEnum.nextElement();
		data.add( Utils.vector( name, props.getProperty( name.toString() ) ) );
	}
	
	table.getXTableModel().setDataVector( data, Utils.vector( "Property name", "Property value" ) );
	table.getRowSorter().setSortKeys( Arrays.asList( new SortKey( 0, SortOrder.ASCENDING ) ) );
	table.packColumnsExceptLast();
	
	p.addCenter( table.createWrapperBox( true, table.createToolBarParams( p ) ) );
	
	return p;
}
 
Example 5
Source Project: visualvm   Source File: BrowserViewSupport.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void initComponents() {
    tableModel = new EventsTableModel();
    table = new ProfilerTable(tableModel, true, true, null);

    table.setFitWidthColumn(-1);
    table.setSorting(0, SortOrder.UNSORTED);
    table.setDefaultSortOrder(SortOrder.ASCENDING);
    table.setDefaultRenderer(Comparable.class, new LabelRenderer());
    
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int selected = table.getSelectedRow();
                if (selected == 0 && values[0] == null) selected = -1; // "loading events..."
                idSelected(selected == -1 ? -1 : ids[table.convertRowIndexToModel(selected)]);
            }
        }
    });
    
    setLayout(new BorderLayout());
    add(new ProfilerTableContainer(table, false, null), BorderLayout.CENTER);
}
 
Example 6
Source Project: visualvm   Source File: TreeTableView.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void initializeColumns(DataType initialSortColumn, SortOrder initialSortOrder, ColumnConfiguration initialColumnConfiguration) {
    if (initialSortColumn != null) {
        SortOrder sortOder = initialSortOrder == null ? SortOrder.UNSORTED : initialSortOrder;
        setSortColumn(initialSortColumn, sortOder);
    }
    
    if (initialColumnConfiguration != null)
        configureColumns(initialColumnConfiguration);
}
 
Example 7
/**
 * Permite ordenar los datos en una columna de la tabla que genera la clase
 *
 * @param column La columna que se desea ordenar
 * @param ascending si se desea un orden ascendente o descendente
 *
 * @since 3.0.3
 */
public void sortColumn(int column, boolean ascending) {
    TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
    table.setRowSorter(sorter);
    List<RowSorter.SortKey> sortKeys = new ArrayList<>();

    if (ascending) {
        sortKeys.add(new RowSorter.SortKey(column, SortOrder.ASCENDING));
    } else {
        sortKeys.add(new RowSorter.SortKey(column, SortOrder.DESCENDING));
    }

    sorter.setSortKeys(sortKeys);
    sorter.sort();
}
 
Example 8
Source Project: visualvm   Source File: MoreObjectsNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
private HeapViewerNode[] computeChildren(int containerIndex, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {            
//        long start = System.currentTimeMillis();
//        try {
        
        // No sorting - plain fetch
        SortOrder sortOrder = sortOrders == null || sortOrders.isEmpty() ? null : sortOrders.get(0);
        if (sortOrder == null || sortOrder.equals(SortOrder.UNSORTED)) return MoreObjectsNode.this.loadChildren(containerIndex, progress);

        // Sorting by count or own size - plain fetch
        DataType dataType = dataTypes == null || dataTypes.isEmpty() ? null : dataTypes.get(0);
        if (dataType == null || !sorts(dataType)) return MoreObjectsNode.this.loadChildren(containerIndex, progress);

        // Sorting - must resolve instanceIDs
        T[] objects = MoreObjectsNode.this.getObjects(containerIndex, heap, null, dataType, sortOrder, progress);
        
//        System.err.println(">>> Children: " + Arrays.toString(objects));
        Thread worker = Thread.currentThread();
        HeapViewerNode[] nodes = new HeapViewerNode[objects.length];
        for (int i = 0; i < nodes.length; i++) {
//            System.err.println(">>> Creating node at idx " + i + " from object " + objects[i]);
            nodes[i] = createNode(objects[i]);
            if (worker.isInterrupted()) throw new InterruptedException();
        }

        return nodes;
        
//        } finally {
//            System.err.println(">>> Container " + containerIndex + " computed in " + (System.currentTimeMillis() - start));
//        }
    }
 
Example 9
Source Project: jdk8u60   Source File: DefaultRowSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reverses the sort order from ascending to descending (or
 * descending to ascending) if the specified column is already the
 * primary sorted column; otherwise, makes the specified column
 * the primary sorted column, with an ascending sort order.  If
 * the specified column is not sortable, this method has no
 * effect.
 *
 * @param column index of the column to make the primary sorted column,
 *        in terms of the underlying model
 * @throws IndexOutOfBoundsException {@inheritDoc}
 * @see #setSortable(int,boolean)
 * @see #setMaxSortKeys(int)
 */
public void toggleSortOrder(int column) {
    checkColumn(column);
    if (isSortable(column)) {
        List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
        SortKey sortKey;
        int sortIndex;
        for (sortIndex = keys.size() - 1; sortIndex >= 0; sortIndex--) {
            if (keys.get(sortIndex).getColumn() == column) {
                break;
            }
        }
        if (sortIndex == -1) {
            // Key doesn't exist
            sortKey = new SortKey(column, SortOrder.ASCENDING);
            keys.add(0, sortKey);
        }
        else if (sortIndex == 0) {
            // It's the primary sorting key, toggle it
            keys.set(0, toggle(keys.get(0)));
        }
        else {
            // It's not the first, but was sorted on, remove old
            // entry, insert as first with ascending.
            keys.remove(sortIndex);
            keys.add(0, new SortKey(column, SortOrder.ASCENDING));
        }
        if (keys.size() > getMaxSortKeys()) {
            keys = keys.subList(0, getMaxSortKeys());
        }
        setSortKeys(keys);
    }
}
 
Example 10
Source Project: visualvm   Source File: JavaClassesProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static HeapViewerNode[] getHeapPackages(HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
    List<HeapViewerNode> nodes = new ArrayList();
    Map<String, ClassesContainer.Objects> packages = new HashMap();
    
    Thread worker = Thread.currentThread();
    
    List<JavaClass> classes = heap.getAllClasses();
    for (JavaClass cls : classes) {
        String className = cls.getName();
        int nameIdx = className.lastIndexOf('.');
        if (nameIdx == -1) {
            ClassNode clsn = new ClassNode(cls);
            if (viewFilter == null || viewFilter.passes(clsn, heap)) nodes.add(clsn);
        } else {
            if (viewFilter != null && !viewFilter.passes(new ClassNode(cls), heap)) continue;
            
            String pkgName = className.substring(0, nameIdx);
            ClassesContainer.Objects node = packages.get(pkgName);
            if (node == null) {
                node = new ClassesContainer.Objects(pkgName);
                nodes.add(node);
                packages.put(pkgName, node);
            }
            node.add(cls, heap);
        }
        if (worker.isInterrupted()) throw new InterruptedException();
    }
    
    return nodes.isEmpty() ? new HeapViewerNode[] { new TextNode(Classes_Messages.getNoPackagesString(viewFilter)) } :
                             nodes.toArray(HeapViewerNode.NO_NODES);
}
 
Example 11
/**
 * Reverses the sort order from ascending to descending (or
 * descending to ascending) if the specified column is already the
 * primary sorted column; otherwise, makes the specified column
 * the primary sorted column, with an ascending sort order.  If
 * the specified column is not sortable, this method has no
 * effect.
 *
 * @param column index of the column to make the primary sorted column,
 *        in terms of the underlying model
 * @throws IndexOutOfBoundsException {@inheritDoc}
 * @see #setSortable(int,boolean)
 * @see #setMaxSortKeys(int)
 */
public void toggleSortOrder(int column) {
    checkColumn(column);
    if (isSortable(column)) {
        List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
        SortKey sortKey;
        int sortIndex;
        for (sortIndex = keys.size() - 1; sortIndex >= 0; sortIndex--) {
            if (keys.get(sortIndex).getColumn() == column) {
                break;
            }
        }
        if (sortIndex == -1) {
            // Key doesn't exist
            sortKey = new SortKey(column, SortOrder.ASCENDING);
            keys.add(0, sortKey);
        }
        else if (sortIndex == 0) {
            // It's the primary sorting key, toggle it
            keys.set(0, toggle(keys.get(0)));
        }
        else {
            // It's not the first, but was sorted on, remove old
            // entry, insert as first with ascending.
            keys.remove(sortIndex);
            keys.add(0, new SortKey(column, SortOrder.ASCENDING));
        }
        if (keys.size() > getMaxSortKeys()) {
            keys = keys.subList(0, getMaxSortKeys());
        }
        setSortKeys(keys);
    }
}
 
Example 12
Source Project: netbeans   Source File: NetworkMonitorTopComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void toggleSortOrder(int column) {
    List<? extends SortKey> sortKeys = getSortKeys();
    if (!sortKeys.isEmpty()) {
        SortKey sortKey = sortKeys.get(0);
        if (sortKey.getColumn() == column && sortKey.getSortOrder() == SortOrder.DESCENDING) {
            setSortKeys(null);
            return;
        }
    }
    super.toggleSortOrder(column);
}
 
Example 13
Source Project: netbeans   Source File: ProfilerRowSorter.java    License: Apache License 2.0 5 votes vote down vote up
public void toggleSortOrder(int column) {
    // UNSORTED not allowed for sorting columns (default)
    if (!allowsThreeStateColumns()) {
        super.toggleSortOrder(column);
        return;
    }
    
    // Switching from one column to another
    if (getSortColumn() != column) {
        super.toggleSortOrder(column);
        return;
    }
    
    // Toggling from default sort order
    SortOrder so = getSortOrder();
    if (Objects.equals(getDefaultSortOrder(column), so)) {
        super.toggleSortOrder(column);
        return;
    }
    
    // Resetting UNSORTED, use default sort order
    if (Objects.equals(SortOrder.UNSORTED, so)) {
        setSortColumn(column);
        return;
    }
    
    // Toggling from second sort order, switch to UNSORTED
    setSortColumn(column, SortOrder.UNSORTED);
}
 
Example 14
private void initComponents() {
    setLayout(new BorderLayout());
    setOpaque(false);
    
    if (!hasData) {
        setLayout(new BorderLayout());
        add(MessageComponent.noData("Per thread allocations", JFRSnapshotSamplerViewProvider.ThreadAllocationsChecker.checkedTypes()), BorderLayout.CENTER);
    } else {
        tableModel = new TreadsAllocTableModel();
        table = new ProfilerTable(tableModel, true, true, null);

        table.setMainColumn(0);
        table.setFitWidthColumn(0);

        table.setSortColumn(1);
        table.setDefaultSortOrder(SortOrder.DESCENDING);
        table.setDefaultSortOrder(0, SortOrder.ASCENDING);

        renderers = new HideableBarRenderer[1];
        renderers[0] = new HideableBarRenderer(new NumberPercentRenderer(Formatters.bytesFormat()));

        LabelRenderer threadRenderer = new LabelRenderer();
        threadRenderer.setIcon(Icons.getIcon(ProfilerIcons.THREAD));
        threadRenderer.setFont(threadRenderer.getFont().deriveFont(Font.BOLD));

        table.setColumnRenderer(0, threadRenderer);
        table.setColumnRenderer(1, renderers[0]);

        add(new ProfilerTableContainer(table, false, null), BorderLayout.CENTER);
    }
}
 
Example 15
Source Project: visualvm   Source File: ProfilerRowSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void toggleSortOrder(int column) {
    // UNSORTED not allowed for sorting columns (default)
    if (!allowsThreeStateColumns()) {
        super.toggleSortOrder(column);
        return;
    }
    
    // Switching from one column to another
    if (getSortColumn() != column) {
        super.toggleSortOrder(column);
        return;
    }
    
    // Toggling from default sort order
    SortOrder so = getSortOrder();
    if (Objects.equals(getDefaultSortOrder(column), so)) {
        super.toggleSortOrder(column);
        return;
    }
    
    // Resetting UNSORTED, use default sort order
    if (Objects.equals(SortOrder.UNSORTED, so)) {
        setSortColumn(column);
        return;
    }
    
    // Toggling from second sort order, switch to UNSORTED
    setSortColumn(column, SortOrder.UNSORTED);
}
 
Example 16
Source Project: visualvm   Source File: ProfilerTable.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected TableRowSorter createRowSorter() {
    ProfilerRowSorter s = new ProfilerRowSorter(getModel());
    s.setStringConverter(new TableStringConverter() {
        public String toString(TableModel model, int row, int column) {
            return getModelStringValue(row, column);
        }
    });
    s.setDefaultSortOrder(SortOrder.DESCENDING);
    s.setSortColumn(0);
    return s;
}
 
Example 17
Source Project: openjdk-8   Source File: DefaultRowSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reverses the sort order from ascending to descending (or
 * descending to ascending) if the specified column is already the
 * primary sorted column; otherwise, makes the specified column
 * the primary sorted column, with an ascending sort order.  If
 * the specified column is not sortable, this method has no
 * effect.
 *
 * @param column index of the column to make the primary sorted column,
 *        in terms of the underlying model
 * @throws IndexOutOfBoundsException {@inheritDoc}
 * @see #setSortable(int,boolean)
 * @see #setMaxSortKeys(int)
 */
public void toggleSortOrder(int column) {
    checkColumn(column);
    if (isSortable(column)) {
        List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
        SortKey sortKey;
        int sortIndex;
        for (sortIndex = keys.size() - 1; sortIndex >= 0; sortIndex--) {
            if (keys.get(sortIndex).getColumn() == column) {
                break;
            }
        }
        if (sortIndex == -1) {
            // Key doesn't exist
            sortKey = new SortKey(column, SortOrder.ASCENDING);
            keys.add(0, sortKey);
        }
        else if (sortIndex == 0) {
            // It's the primary sorting key, toggle it
            keys.set(0, toggle(keys.get(0)));
        }
        else {
            // It's not the first, but was sorted on, remove old
            // entry, insert as first with ascending.
            keys.remove(sortIndex);
            keys.add(0, new SortKey(column, SortOrder.ASCENDING));
        }
        if (keys.size() > getMaxSortKeys()) {
            keys = keys.subList(0, getMaxSortKeys());
        }
        setSortKeys(keys);
    }
}
 
Example 18
Source Project: Java8CN   Source File: DefaultRowSorter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Reverses the sort order from ascending to descending (or
 * descending to ascending) if the specified column is already the
 * primary sorted column; otherwise, makes the specified column
 * the primary sorted column, with an ascending sort order.  If
 * the specified column is not sortable, this method has no
 * effect.
 *
 * @param column index of the column to make the primary sorted column,
 *        in terms of the underlying model
 * @throws IndexOutOfBoundsException {@inheritDoc}
 * @see #setSortable(int,boolean)
 * @see #setMaxSortKeys(int)
 */
public void toggleSortOrder(int column) {
    checkColumn(column);
    if (isSortable(column)) {
        List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
        SortKey sortKey;
        int sortIndex;
        for (sortIndex = keys.size() - 1; sortIndex >= 0; sortIndex--) {
            if (keys.get(sortIndex).getColumn() == column) {
                break;
            }
        }
        if (sortIndex == -1) {
            // Key doesn't exist
            sortKey = new SortKey(column, SortOrder.ASCENDING);
            keys.add(0, sortKey);
        }
        else if (sortIndex == 0) {
            // It's the primary sorting key, toggle it
            keys.set(0, toggle(keys.get(0)));
        }
        else {
            // It's not the first, but was sorted on, remove old
            // entry, insert as first with ascending.
            keys.remove(sortIndex);
            keys.add(0, new SortKey(column, SortOrder.ASCENDING));
        }
        if (keys.size() > getMaxSortKeys()) {
            keys = keys.subList(0, getMaxSortKeys());
        }
        setSortKeys(keys);
    }
}
 
Example 19
Source Project: hottub   Source File: DefaultRowSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reverses the sort order from ascending to descending (or
 * descending to ascending) if the specified column is already the
 * primary sorted column; otherwise, makes the specified column
 * the primary sorted column, with an ascending sort order.  If
 * the specified column is not sortable, this method has no
 * effect.
 *
 * @param column index of the column to make the primary sorted column,
 *        in terms of the underlying model
 * @throws IndexOutOfBoundsException {@inheritDoc}
 * @see #setSortable(int,boolean)
 * @see #setMaxSortKeys(int)
 */
public void toggleSortOrder(int column) {
    checkColumn(column);
    if (isSortable(column)) {
        List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
        SortKey sortKey;
        int sortIndex;
        for (sortIndex = keys.size() - 1; sortIndex >= 0; sortIndex--) {
            if (keys.get(sortIndex).getColumn() == column) {
                break;
            }
        }
        if (sortIndex == -1) {
            // Key doesn't exist
            sortKey = new SortKey(column, SortOrder.ASCENDING);
            keys.add(0, sortKey);
        }
        else if (sortIndex == 0) {
            // It's the primary sorting key, toggle it
            keys.set(0, toggle(keys.get(0)));
        }
        else {
            // It's not the first, but was sorted on, remove old
            // entry, insert as first with ascending.
            keys.remove(sortIndex);
            keys.add(0, new SortKey(column, SortOrder.ASCENDING));
        }
        if (keys.size() > getMaxSortKeys()) {
            keys = keys.subList(0, getMaxSortKeys());
        }
        setSortKeys(keys);
    }
}
 
Example 20
Source Project: visualvm   Source File: TruffleThreadsView.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TruffleThreadsView(TruffleLanguage language, HeapContext context, HeapViewerActions actions) {
    super(idFromLanguage(language), Bundle.TruffleThreadsView_Name(), Bundle.TruffleThreadsView_Description(), iconFromLanguage(language), 300);
    
    Heap heap = context.getFragment().getHeap();
    
    final TruffleThreadsProvider threadsProvider = new TruffleThreadsProvider(language);
    
    objectsView = new PluggableTreeTableView(getID() + OBJECTS_ID, context, actions, TreeTableViewColumn.instances(heap, false)) {
        @Override
        protected HeapViewerNode[] computeData(RootNode root, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
            return threadsProvider.getThreadsObjects(root, heap, viewID, viewFilter, dataTypes, sortOrders, progress);
        }
        protected void childrenChanged() {
            CCTNode[] children = getRoot().getChildren();
            for (CCTNode child : children) expandNode((HeapViewerNode)child);
        }
    };
    objectsView.setViewName(getName());
    
    htmlView = new HTMLView(getID() + HTML_ID, context, actions, "<br>&nbsp;&nbsp;" + Bundle.TruffleThreadsView_ComputingThreads()) { // NOI18N
        protected String computeData(HeapContext context, String viewID) {
            return threadsProvider.getThreadsHTML(context);
        }
        protected HeapViewerNode nodeForURL(URL url, HeapContext context) {
            return threadsProvider.getNodeForURL(url, context);
        }
    };
}
 
Example 21
Source Project: visualvm   Source File: SocketIOViewSupport.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void initComponents() {
    tableModel = new DataModel();
    table = new ProfilerTreeTable(tableModel, true, true, new int[] { 0 });
    
    table.setRootVisible(false);
    table.setShowsRootHandles(true);

    table.setMainColumn(0);
    table.setFitWidthColumn(0);

    table.setSortColumn(1);
    table.setDefaultSortOrder(SortOrder.DESCENDING);
    table.setDefaultSortOrder(0, SortOrder.ASCENDING);
    
    SocketIORenderers.NameRenderer nameRenderer = new SocketIORenderers.NameRenderer();
    table.setTreeCellRenderer(nameRenderer);
    
    SocketIORenderers.TotalTimeRenderer totalTimeRenderer = new SocketIORenderers.TotalTimeRenderer();
    table.setColumnRenderer(1, totalTimeRenderer);
    table.setDefaultColumnWidth(1, totalTimeRenderer.getPreferredWidth());
    table.setColumnVisibility(1, SocketIORenderers.TotalTimeRenderer.isInitiallyVisible());
    
    SocketIORenderers.ReadTimeRenderer readTimeRenderer = new SocketIORenderers.ReadTimeRenderer();
    table.setColumnRenderer(2, readTimeRenderer);
    table.setDefaultColumnWidth(2, readTimeRenderer.getPreferredWidth());
    table.setColumnVisibility(2, SocketIORenderers.ReadTimeRenderer.isInitiallyVisible());
    
    SocketIORenderers.MaxReadTimeRenderer maxReadTimeRenderer = new SocketIORenderers.MaxReadTimeRenderer();
    table.setColumnRenderer(3, maxReadTimeRenderer);
    table.setDefaultColumnWidth(3, maxReadTimeRenderer.getPreferredWidth());
    table.setColumnVisibility(3, SocketIORenderers.MaxReadTimeRenderer.isInitiallyVisible());
    
    SocketIORenderers.WriteTimeRenderer writeTimeRenderer = new SocketIORenderers.WriteTimeRenderer();
    table.setColumnRenderer(4, writeTimeRenderer);
    table.setDefaultColumnWidth(4, writeTimeRenderer.getPreferredWidth());
    table.setColumnVisibility(4, SocketIORenderers.WriteTimeRenderer.isInitiallyVisible());
    
    SocketIORenderers.MaxWriteTimeRenderer maxWriteTimeRenderer = new SocketIORenderers.MaxWriteTimeRenderer();
    table.setColumnRenderer(5, maxWriteTimeRenderer);
    table.setDefaultColumnWidth(5, maxWriteTimeRenderer.getPreferredWidth());
    table.setColumnVisibility(5, SocketIORenderers.MaxWriteTimeRenderer.isInitiallyVisible());
    
    SocketIORenderers.TotalCountRenderer totalCountRenderer = new SocketIORenderers.TotalCountRenderer();
    table.setColumnRenderer(6, totalCountRenderer);
    table.setDefaultColumnWidth(6, totalCountRenderer.getPreferredWidth());
    table.setColumnVisibility(6, SocketIORenderers.TotalCountRenderer.isInitiallyVisible());
    
    SocketIORenderers.ReadCountRenderer readCountRenderer = new SocketIORenderers.ReadCountRenderer();
    table.setColumnRenderer(7, readCountRenderer);
    table.setDefaultColumnWidth(7, readCountRenderer.getPreferredWidth());
    table.setColumnVisibility(7, SocketIORenderers.ReadCountRenderer.isInitiallyVisible());
    
    SocketIORenderers.WriteCountRenderer writeCountRenderer = new SocketIORenderers.WriteCountRenderer();
    table.setColumnRenderer(8, writeCountRenderer);
    table.setDefaultColumnWidth(8, writeCountRenderer.getPreferredWidth());
    table.setColumnVisibility(8, SocketIORenderers.WriteCountRenderer.isInitiallyVisible());
    
    SocketIORenderers.ReadBytesRenderer readBytesRenderer = new SocketIORenderers.ReadBytesRenderer();
    table.setColumnRenderer(9, readBytesRenderer);
    table.setDefaultColumnWidth(9, readBytesRenderer.getPreferredWidth());
    table.setColumnVisibility(9, SocketIORenderers.ReadBytesRenderer.isInitiallyVisible());
    
    SocketIORenderers.WriteBytesRenderer writeBytesRenderer = new SocketIORenderers.WriteBytesRenderer();
    table.setColumnRenderer(10, writeBytesRenderer);
    table.setDefaultColumnWidth(10, writeBytesRenderer.getPreferredWidth());
    table.setColumnVisibility(10, SocketIORenderers.WriteBytesRenderer.isInitiallyVisible());
    
    setLayout(new BorderLayout());
    add(new ProfilerTableContainer(table, false, null), BorderLayout.CENTER);
}
 
Example 22
Source Project: jdk1.8-source-analysis   Source File: DefaultRowSorter.java    License: Apache License 2.0 4 votes vote down vote up
private SortKey toggle(SortKey key) {
    if (key.getSortOrder() == SortOrder.ASCENDING) {
        return new SortKey(key.getColumn(), SortOrder.DESCENDING);
    }
    return new SortKey(key.getColumn(), SortOrder.ASCENDING);
}
 
Example 23
Source Project: jdk1.8-source-analysis   Source File: DefaultRowSorter.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isUnsorted() {
    List<? extends SortKey> keys = getSortKeys();
    int keySize = keys.size();
    return (keySize == 0 || keys.get(0).getSortOrder() ==
            SortOrder.UNSORTED);
}
 
Example 24
public ClassHierarchyPlugin(HeapContext context, HeapViewerActions actions) {
    super(Bundle.ClassHierarchyPlugin_Name(), Bundle.ClassHierarchyPlugin_Description(), Icons.getIcon(HeapWalkerIcons.CLASSES));
    
    heap = context.getFragment().getHeap();
    
    objectsView = new TreeTableView("java_objects_hierarchy", context, actions, TreeTableViewColumn.classesPlain(heap)) { // NOI18N
        protected HeapViewerNode[] computeData(RootNode root, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
            JavaClass javaClass;
            synchronized (objectsView) { javaClass = selected; }
            
            if (javaClass != null) {
                
                if (javaClass == EMPTY_CLASS) return new HeapViewerNode[] { new TextNode(Bundle.ClassHierarchyPlugin_NoInformation()) };
                
                if (javaClass.isArray()) {
                    String className = javaClass.getName().replace("[]", ""); // NOI18N
                    JavaClass plainClass = heap.getJavaClassByName(className);
                    if (plainClass != null) javaClass = plainClass;
                }
                
                SuperClassNode node = null;
                SuperClassNode firstNode = null;
                SuperClassNode previousNode = null;

                Thread worker = Thread.currentThread();
                while (javaClass != null) {
                    node = new SuperClassNode(javaClass);
                    if (firstNode == null) firstNode = node;
                    else previousNode.setChildren(new HeapViewerNode[] { node });

                    javaClass = javaClass.getSuperClass();

                    previousNode = node;
                    
                    if (worker.isInterrupted()) throw new InterruptedException();
                }

                node.setChildren(HeapViewerNode.NO_NODES);
                return new HeapViewerNode[] { firstNode };
            }
            
            return new HeapViewerNode[] { new TextNode(Bundle.ClassHierarchyPlugin_NoSelection()) };
        }
        protected void childrenChanged() {
            HeapViewerNode root = (HeapViewerNode)getRoot();
            while (root != null) {
                expandNode(root);
                root = root.getNChildren() > 0 ? (HeapViewerNode)root.getChild(0) : null;
            }
        }
    };
}
 
Example 25
private void initComponents() {
            model = new DataModel();
            
            table = new ProfilerTable(model, true, true, null);
            
            table.setMainColumn(0);
            table.setFitWidthColumn(0);

            table.setDefaultSortOrder(SortOrder.ASCENDING);
            table.setSortColumn(1);
            
            RecordingRenderers.NameRenderer nameRenderer = new RecordingRenderers.NameRenderer();
            table.setColumnRenderer(0, nameRenderer);
            
            RecordingRenderers.IdRenderer idRenderer = new RecordingRenderers.IdRenderer();
            table.setColumnRenderer(1, idRenderer);
            table.setDefaultColumnWidth(1, idRenderer.getPreferredWidth());
            table.setColumnVisibility(1, RecordingRenderers.IdRenderer.isInitiallyVisible());
            
            RecordingRenderers.StartRenderer startRenderer = new RecordingRenderers.StartRenderer(jfrModel);
            table.setColumnRenderer(2, startRenderer);
            table.setDefaultColumnWidth(2, startRenderer.getPreferredWidth());
            table.setColumnVisibility(2, RecordingRenderers.TimeRenderer.isInitiallyVisible());
            
            RecordingRenderers.DurationRenderer durationRenderer = new RecordingRenderers.DurationRenderer();
            RecordingRenderers.SizeRenderer sizeRenderer = new RecordingRenderers.SizeRenderer();
            RecordingRenderers.AgeRenderer ageRenderer = new RecordingRenderers.AgeRenderer();
            int commonWidth = Math.max(durationRenderer.getPreferredWidth(), sizeRenderer.getPreferredWidth());
            commonWidth = Math.max(commonWidth, ageRenderer.getPreferredWidth());
            table.setColumnRenderer(3, durationRenderer);
            table.setDefaultColumnWidth(3, commonWidth);
            table.setColumnVisibility(3, RecordingRenderers.DurationRenderer.isInitiallyVisible());
            
            table.setColumnRenderer(4, sizeRenderer);
            table.setDefaultColumnWidth(4, commonWidth);
            table.setColumnVisibility(4, RecordingRenderers.SizeRenderer.isInitiallyVisible());
            
            table.setColumnRenderer(5, ageRenderer);
            table.setDefaultColumnWidth(5, commonWidth);
            table.setColumnVisibility(5, RecordingRenderers.AgeRenderer.isInitiallyVisible());
            
            RecordingRenderers.DestinationRenderer destinationRenderer = new RecordingRenderers.DestinationRenderer();
            table.setColumnRenderer(6, destinationRenderer);
            table.setDefaultColumnWidth(6, destinationRenderer.getPreferredWidth());
            table.setColumnVisibility(6, RecordingRenderers.DestinationRenderer.isInitiallyVisible());
            
//            RecordingRenderers.ThreadRenderer threadRenderer = new RecordingRenderers.ThreadRenderer();
//            table.setColumnRenderer(7, threadRenderer);
//            table.setDefaultColumnWidth(7, threadRenderer.getPreferredWidth());
//            table.setColumnVisibility(7, RecordingRenderers.ThreadRenderer.isInitiallyVisible());
            
            setLayout(new BorderLayout());
            add(new ProfilerTableContainer(table, false, null), BorderLayout.CENTER);
        }
 
Example 26
Source Project: visualvm   Source File: TablesSelector.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void populatePopup() {
    JPanel content = new JPanel(new BorderLayout());
    
    JLabel hint = new JLabel(SELECT_TABLES, JLabel.LEADING);
    hint.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0));
    content.add(hint, BorderLayout.NORTH);

    final SelectedTablesModel tablesModel = new SelectedTablesModel();
    final ProfilerTable tablesTable = new ProfilerTable(tablesModel, true, false, null);
    tablesTable.setColumnToolTips(new String[] {
        COLUMN_SELECTED_TOOLTIP,
        COLUMN_TABLE_TOOLTIP });
    tablesTable.setMainColumn(1);
    tablesTable.setFitWidthColumn(1);
    tablesTable.setDefaultSortOrder(1, SortOrder.ASCENDING);
    tablesTable.setSortColumn(1);
    tablesTable.setFixedColumnSelection(0); // #268298 - make sure SPACE always hits the Boolean column
    tablesTable.setColumnRenderer(0, new CheckBoxRenderer());
    LabelRenderer projectRenderer = new LabelRenderer();
    tablesTable.setColumnRenderer(1, projectRenderer);
    int w = new JLabel(tablesTable.getColumnName(0)).getPreferredSize().width;
    tablesTable.setDefaultColumnWidth(0, w + 15);
    int h = tablesTable.getRowHeight() * 8;
    h += tablesTable.getTableHeader().getPreferredSize().height;
    projectRenderer.setText("A LONGEST EXPECTED TABLE NAME A LONGEST EXPECTED TABLE NAME"); // NOI18N
    Dimension prefSize = new Dimension(w + projectRenderer.getPreferredSize().width, h);
    tablesTable.setPreferredScrollableViewportSize(prefSize);
    ProfilerTableContainer tableContainer = new ProfilerTableContainer(tablesTable, true, null);
    JPanel tableContent = new JPanel(new BorderLayout());
    tableContent.setBorder(BorderFactory.createEmptyBorder(0, 0, 4, 0));
    tableContent.add(tableContainer, BorderLayout.CENTER);
    content.add(tableContent, BorderLayout.CENTER);

    JToolBar controls = new FilteringToolbar(FILTER_TABLES) {
        protected void filterChanged() {
            if (isAll()) tablesTable.setRowFilter(null);
            else tablesTable.setRowFilter(new RowFilter() {
                public boolean include(RowFilter.Entry entry) {
                    return passes(entry.getStringValue(1));
                }
            });
        }
    };
    
    controls.add(Box.createHorizontalStrut(2));
    controls.addSeparator();
    controls.add(Box.createHorizontalStrut(3));
    
    selectAll = new SmallButton(" " + ACT_SELECT_ALL + " ") { // NOI18N
        protected void fireActionPerformed(ActionEvent e) {
            super.fireActionPerformed(e);
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    selected.clear();
                    tablesModel.fireTableDataChanged();
                    doSelectionChanged(selected);
                }
            });
        }
    };
    controls.add(selectAll);
    unselectAll = new SmallButton(" " + ACT_UNSELECT_ALL + " ") { // NOI18N
        protected void fireActionPerformed(ActionEvent e) {
            super.fireActionPerformed(e);
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    selected.clear();
                    selected.addAll(Arrays.asList(tables));
                    tablesModel.fireTableDataChanged();
                    doSelectionChanged(selected);
                }
            });
        }
    };
    controls.add(unselectAll);

    content.add(controls, BorderLayout.SOUTH);

    panel = content;
    
    updateSelectionButtons();
}
 
Example 27
@SuppressWarnings("unchecked")
private int compare(int model1, int model2) {
    int column;
    SortOrder sortOrder;
    Object v1, v2;
    int result;

    for (int counter = 0; counter < cachedSortKeys.length; counter++) {
        column = cachedSortKeys[counter].getColumn();
        sortOrder = cachedSortKeys[counter].getSortOrder();
        if (sortOrder == SortOrder.UNSORTED) {
            result = model1 - model2;
        } else {
            // v1 != null && v2 != null
            if (useToString[column]) {
                v1 = getModelWrapper().getStringValueAt(model1, column);
                v2 = getModelWrapper().getStringValueAt(model2, column);
            } else {
                v1 = getModelWrapper().getValueAt(model1, column);
                v2 = getModelWrapper().getValueAt(model2, column);
            }
            // Treat nulls as < then non-null
            if (v1 == null) {
                if (v2 == null) {
                    result = 0;
                } else {
                    result = -1;
                }
            } else if (v2 == null) {
                result = 1;
            } else {
                result = sortComparators[counter].compare(v1, v2);
            }
            if (sortOrder == SortOrder.DESCENDING) {
                result *= -1;
            }
        }
        if (result != 0) {
            return result;
        }
    }
    // If we get here, they're equal. Fallback to model order.
    return model1 - model2;
}
 
Example 28
public HeapViewerNode[] getNodes(HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
    return getNodes(((InstanceNode)parent).getInstance(), parent, heap, viewID, viewFilter, dataTypes, sortOrders, progress);
}
 
Example 29
private boolean isUnsorted() {
    List<? extends SortKey> keys = getSortKeys();
    int keySize = keys.size();
    return (keySize == 0 || keys.get(0).getSortOrder() ==
            SortOrder.UNSORTED);
}
 
Example 30
Source Project: visualvm   Source File: ProjectsSelector.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void populatePopup() {
    JPanel content = new JPanel(new BorderLayout());
    
    JLabel hint = new JLabel(Bundle.ProjectsSelector_selectProjects(), JLabel.LEADING);
    hint.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0));
    content.add(hint, BorderLayout.NORTH);

    final SelectedProjectsModel projectsModel = new SelectedProjectsModel();
    final ProfilerTable projectsTable = new ProfilerTable(projectsModel, true, false, null);
    projectsTable.setColumnToolTips(new String[] {
        Bundle.ProjectsSelector_columnSelectedToolTip(),
        Bundle.ProjectsSelector_columnProjectToolTip() });
    projectsTable.setMainColumn(1);
    projectsTable.setFitWidthColumn(1);
    projectsTable.setDefaultSortOrder(1, SortOrder.ASCENDING);
    projectsTable.setSortColumn(1);
    projectsTable.setFixedColumnSelection(0); // #268298 - make sure SPACE always hits the Boolean column
    projectsTable.setColumnRenderer(0, new CheckBoxRenderer());
    LabelRenderer projectRenderer = new ProjectRenderer();
    projectsTable.setColumnRenderer(1, projectRenderer);
    int w = new JLabel(projectsTable.getColumnName(0)).getPreferredSize().width;
    projectsTable.setDefaultColumnWidth(0, w + 15);
    int h = projectsTable.getRowHeight() * 8;
    h += projectsTable.getTableHeader().getPreferredSize().height;
    projectRenderer.setText("A longest expected project name A longest expected project name"); // NOI18N
    Dimension prefSize = new Dimension(w + projectRenderer.getPreferredSize().width, h);
    projectsTable.setPreferredScrollableViewportSize(prefSize);
    ProfilerTableContainer tableContainer = new ProfilerTableContainer(projectsTable, true, null);
    JPanel tableContent = new JPanel(new BorderLayout());
    tableContent.setBorder(BorderFactory.createEmptyBorder(0, 0, 4, 0));
    tableContent.add(tableContainer, BorderLayout.CENTER);
    content.add(tableContent, BorderLayout.CENTER);

    JToolBar controls = new FilteringToolbar(Bundle.ProjectsSelector_filterProjects()) {
        protected void filterChanged() {
            if (isAll()) projectsTable.setRowFilter(null);
            else projectsTable.setRowFilter(new RowFilter() {
                public boolean include(RowFilter.Entry entry) {
                    return passes(entry.getStringValue(1));
                }
            });
        }
    };

    content.add(controls, BorderLayout.SOUTH);

    panel = content;
}