Skip to content

Commit

Permalink
splitpane to shrink config area
Browse files Browse the repository at this point in the history
  • Loading branch information
newbrough committed Apr 28, 2016
1 parent ace3f9d commit 5abf0db
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 21 deletions.
25 changes: 15 additions & 10 deletions gumshoe-tools/src/main/java/com/dell/gumshoe/tools/Gumshoe.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.dell.gumshoe.tools;

import static com.dell.gumshoe.tools.Swing.flow;

import com.dell.gumshoe.ProbeManager;
import com.dell.gumshoe.stack.Stack;
import com.dell.gumshoe.stats.StatisticAdder;
import com.dell.gumshoe.tools.StatisticsSourcePanel.Listener;
import com.dell.gumshoe.tools.graph.StackGraphPanel;

import static com.dell.gumshoe.tools.Swing.*;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayer;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
Expand Down Expand Up @@ -92,7 +92,6 @@ private Gumshoe(ProbeManager probe, boolean hasMain) {
final StackGraphPanel graph = new StackGraphPanel();

final StatisticsSourcePanel statsRelay = new StatisticsSourcePanel(probe);

statsRelay.addListener(new Listener() {
@Override
public void statisticsLoaded(String time, String type, Map<Stack,StatisticAdder> stats) {
Expand All @@ -112,25 +111,31 @@ public void statisticsLoaded(String time, String type, Map<Stack,StatisticAdder>
final JScrollPane scroll = new JScrollPane(detailField);
detailPanel.add(scroll, BorderLayout.CENTER);

final JPanel statsPanel = flow(statsRelay);

final FilterEditor filterEditor = new FilterEditor();
filterEditor.setGraph(graph);

final JTabbedPane settings = new JTabbedPane();
final JTabbedPane settings = createTabbedPaneWithoutHScroll();
settings.setBorder(BorderFactory.createEmptyBorder(10,5,5,5));
settings.addTab("Collect -->", statsPanel);
settings.addTab("Collect -->", statsRelay);
settings.addTab("--> Filter -->", filterEditor);
settings.addTab("--> Display -->", graph.getOptionEditor());
settings.addTab("--> Examine", detailPanel);

final JPanel settingPanel = new JPanel();
settingPanel.setLayout(new BorderLayout());
settingPanel.add(settings);

final JPanel graphPanel = new JPanel();
graphPanel.setLayout(new BorderLayout());
graphPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
graphPanel.add(graph);

final JSplitPane mainView = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
mainView.setTopComponent(graphPanel);
mainView.setBottomComponent(new JScrollPane(settings, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));

setLayout(new BorderLayout());
add(graphPanel, BorderLayout.CENTER);
add(settings, BorderLayout.SOUTH);
add(mainView, BorderLayout.CENTER);

if( ! hasMain) {
// if this is the only program, click X to exit (otherwise just hide gumshoe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,36 @@
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

public class ProbeSourcePanel extends JPanel implements Listener<StatisticAdder> {
private static final SimpleDateFormat hms = new SimpleDateFormat("HH:mm:ss");

private String lastReceivedType;
private Map<Stack,StatisticAdder> lastReceivedStats;
private String receiveTime;
private final StatisticsSourcePanel parent;

private final JRadioButton ignoreIncoming = new JRadioButton("ignore new samples");
private final JRadioButton dropOldest = new JRadioButton("drop oldest sample", true);
private final JCheckBox sendLive = new JCheckBox("Immediately show newest");
private final JButton sendNow = new JButton("Display selected");
private final JLabel received = new JLabel("No data has been received");
private int sampleCount = 3;
private final DefaultListModel sampleModel = new DefaultListModel();
private final JList sampleList = new JList(sampleModel);
Expand All @@ -59,6 +60,7 @@ public void actionPerformed(ActionEvent e) {
}
});

sampleList.setVisibleRowCount(sampleCount);
sampleList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Expand Down Expand Up @@ -93,13 +95,11 @@ public void actionPerformed(ActionEvent e) {
}
});

final JPanel optionPanel = rows(received, acceptPanel, handleIncoming);

JScrollPane sampleScroll = new JScrollPane(sampleList);
final JPanel optionPanel = rows(acceptPanel, handleIncoming);

setLayout(new BorderLayout());
add(optionPanel, BorderLayout.NORTH);
add(sampleScroll, BorderLayout.CENTER);
add(new JScrollPane(sampleList, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
add(flow(sendNow), BorderLayout.SOUTH);

if(probe!=null) {
Expand Down Expand Up @@ -135,13 +135,11 @@ private boolean canAccept(String sampleType, Map<Stack,StatisticAdder> stats) {
public synchronized void statsReported(String type, Map<Stack,StatisticAdder> stats) {
if(canAccept(type, stats)) {
final Date date = new Date();
receiveTime = hms.format(date);
final Sample sample = new Sample(type, date, stats);
if(sendLive.isSelected()) {
sampleModel.clear();
}
sampleModel.addElement(sample);
received.setText("Received data " + receiveTime);
if(sendLive.isSelected()) {
relayStats(sample);
}
Expand Down Expand Up @@ -171,4 +169,5 @@ public String toString() {
return label;
}
}

}
99 changes: 99 additions & 0 deletions gumshoe-tools/src/main/java/com/dell/gumshoe/tools/Swing.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,63 @@
package com.dell.gumshoe.tools;

import javax.accessibility.AccessibleContext;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.Scrollable;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import java.awt.AWTException;
import java.awt.AWTKeyStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.ImageCapabilities;
import java.awt.MenuComponent;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.dnd.DropTarget;
import java.awt.event.ComponentListener;
import java.awt.event.FocusListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyListener;
import java.awt.event.InputMethodListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelListener;
import java.awt.im.InputContext;
import java.awt.im.InputMethodRequests;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer;
import java.beans.PropertyChangeListener;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.EventListener;
import java.util.Locale;
import java.util.Set;
import java.util.TimerTask;

/** utility methods to simplify layout and construction of swing GUI */
public class Swing {
Expand Down Expand Up @@ -106,4 +153,56 @@ public static JPanel titled(String title, JComponent content) {
return out;
}
}

public static JTabbedPane createTabbedPaneWithoutHScroll() {
return new JTabbedWithoutHScroll();
}

// track down layout issues by showing following size through container hierarchy
public static void debugWidth(Component c) {
int lastWidth = c.getWidth();
while(c!=null) {
final String className = c.getClass().getName();
final String[] parts = className.split("\\.");
final String lastPart = parts[parts.length-1];
int thisWidth = c.getWidth();
final float percent = ((float)Math.abs(thisWidth-lastWidth))/lastWidth;
boolean delta = percent > .1;
if(delta) {
System.out.printf(">> %25s %5d\n", lastPart, c.getWidth());
} else {
System.out.printf("%28s %5d %.2f\n", lastPart, c.getWidth(), percent);
}
c = c.getParent();
lastWidth = thisWidth;
}
System.out.println("-----");
}

private static class JTabbedWithoutHScroll extends JTabbedPane implements Scrollable {
@Override
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}

@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 1;
}

@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 10;
}

@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}

@Override
public boolean getScrollableTracksViewportHeight() {
return false;
}
}
}

0 comments on commit 5abf0db

Please sign in to comment.