GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — method-tracer/ControlPanel.java at main · flight-recorder/method-tracer Expand file tree/ Copy pathControlPanel.javaMore file actions 149 lines (139 loc) · 6.16 KB / Copy pathControlPanel.javaFile metadata and controls149 lines (139 loc) · 6.16 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 /* * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.io.IOException; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JTextField; import javax.swing.JToggleButton; import javax.swing.SwingConstants; import static java.awt.GridBagConstraints.HORIZONTAL; import static java.awt.GridBagConstraints.LINE_END; import static java.awt.GridBagConstraints.LINE_START; import static java.awt.GridBagConstraints.NONE; import static java.awt.GridBagConstraints.VERTICAL; @SuppressWarnings("serial") final class ControlPanel extends JPanel { private static final String FILTER_TOOLTIP_HTML = """ <html> A filter can be:<br> • an annotation (<code>@jakarta.ws.rs.GET</code>)<br> • a fully qualified class name (<code>com.example.Foo</code>)<br> • a fully qualified method reference (<code>java.lang.HashMap::resize</code>)<br> • a class initializer (<code>::<clinit></code>)<br> Use <code><init></code> for constructors. Separate multiple filters with semicolon. </html> """; private static final String RESUME_UPDATE_TEXT = "Resume Update"; private static final String PAUSE_UPDATE_TEXT = "Pause Update"; private final JLabel filterLabel = new JLabel("Filter:"); private final JTextField filterField = new JTextField("java.lang.String"); private final JButton applyButton = new JButton("Apply"); private final JButton startButton = new JButton("Start"); private final JButton stopButton = new JButton("Stop"); private final JToggleButton pauseToggle = new JToggleButton(PAUSE_UPDATE_TEXT); private final JSeparator separator = new JSeparator(SwingConstants.VERTICAL); private final JButton sourceButton = new JButton("Select Java Virtual Machine ..."); private final MethodTracer methodTracer; ControlPanel(MethodTracer methodTracer) { this.methodTracer = methodTracer; setLayout(new GridBagLayout()); addComponents(); wireActions(); this.methodTracer.addUIListener(this::updateButtons); updateButtons(); } private void addComponents() { add(filterLabel, gbc(0, 0, LINE_END, NONE, 0.0)); add(filterField, gbc(1, 0, LINE_START, HORIZONTAL, 1.0)); add(applyButton, gbc(2, 0, LINE_END, NONE, 0.0)); add(startButton, gbc(3, 30, LINE_END, NONE, 0.0)); add(stopButton, gbc(4, 0, LINE_END, NONE, 0.0)); add(pauseToggle, gbc(5, 0, LINE_END, NONE, 0.0)); add(separator, gbc(6, 100, LINE_END, VERTICAL, 0.0)); add(sourceButton, gbc(7, 0, LINE_END, NONE, 0.0)); filterField.setToolTipText(FILTER_TOOLTIP_HTML); } private void wireActions() { applyButton.addActionListener(_ -> methodTracer.setTimingFilter(filterField.getText())); startButton.addActionListener(_ -> { try { methodTracer.start(); methodTracer.setTimingFilter(filterField.getText()); updateButtons(); } catch (IOException e) { showError(startButton, "Stream Error", "Error when starting a stream:\n" + e.getMessage()); } }); stopButton.addActionListener(_ -> methodTracer.stop()); pauseToggle.addActionListener(_ -> { if (pauseToggle.isSelected()) { methodTracer.pause(); pauseToggle.setText(RESUME_UPDATE_TEXT); } else { methodTracer.resume(); pauseToggle.setText(PAUSE_UPDATE_TEXT); } }); sourceButton.addActionListener(_ -> { StreamResource sr = StreamResource.ofDialog(); if (sr != null) { methodTracer.setStreamResource(sr); } }); } private void updateButtons() { boolean running = methodTracer.isRunning(); sourceButton.setEnabled(!running); startButton.setEnabled(!running); stopButton.setEnabled(running); applyButton.setEnabled(running); pauseToggle.setEnabled(running); if (!running) { pauseToggle.setSelected(false); pauseToggle.setText(PAUSE_UPDATE_TEXT); } } private static void showError(Component parent, String title, String message) { JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE); } private static GridBagConstraints gbc(int x, int leftGap, int anchor, int fill, double weightx) { GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = x; gbc.gridy = 0; gbc.anchor = anchor; gbc.fill = fill; gbc.weightx = weightx; gbc.insets = new Insets(0, leftGap, 0, 0); return gbc; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |