001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.gui.se.pane;
017
018 import java.awt.Container;
019 import java.awt.Dimension;
020 import java.awt.event.ActionEvent;
021 import java.awt.event.ActionListener;
022
023 import javax.swing.BoxLayout;
024 import javax.swing.JButton;
025 import javax.swing.JFrame;
026 import javax.swing.JPanel;
027 import javax.swing.JToggleButton;
028
029 import org.qedeq.base.trace.Trace;
030 import org.qedeq.base.utility.YodaUtility;
031 import org.qedeq.gui.se.util.GuiHelper;
032
033 import com.jgoodies.forms.builder.ButtonBarBuilder;
034
035 /**
036 * Configures the application.
037 *
038 * @author Michael Meyling
039 */
040
041 public class ProcessWindow extends JFrame {
042
043 /** This class. */
044 private static final Class CLASS = ProcessWindow.class;
045
046 /** Here is our process list. */
047 private ProcessListPane processList;
048
049 /**
050 * Creates new Panel.
051 */
052 public ProcessWindow() {
053 super("Processes");
054 final String method = "Constructor";
055 Trace.begin(CLASS, this, method);
056 try {
057 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
058 setupView();
059 updateView();
060 } catch (Throwable e) {
061 Trace.fatal(CLASS, this, "Initalization of PreferencesDialog failed.", method, e);
062 } finally {
063 Trace.end(CLASS, this, method);
064 }
065 }
066
067
068 /**
069 * Assembles the GUI components of the panel.
070 */
071 public final void setupView() {
072 setIconImage(GuiHelper.readImageIcon("tango/16x16/categories/applications-system.png")
073 .getImage());
074 final Container content = getContentPane();
075 content.setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
076 JPanel allOptions = new JPanel();
077 allOptions.setBorder(GuiHelper.getEmptyBorder());
078 allOptions.setLayout(new BoxLayout(allOptions, BoxLayout.Y_AXIS));
079 processList = new ProcessListPane();
080 allOptions.add(processList);
081 content.add(allOptions);
082
083 ButtonBarBuilder bbuilder = ButtonBarBuilder.createLeftToRightBuilder();
084
085 JButton stackTrace = null;
086
087 if (YodaUtility.existsMethod(Thread.class, "getStackTrace", new Class[] {})) {
088 stackTrace = new JButton("Stacktrace");
089 stackTrace.addActionListener(new ActionListener() {
090 public void actionPerformed(final ActionEvent actionEvent) {
091 ProcessWindow.this.processList.stackTraceSelected();
092 }
093 });
094 }
095
096 final JButton details = new JButton("Details");
097 details.addActionListener(new ActionListener() {
098 public void actionPerformed(final ActionEvent actionEvent) {
099 ProcessWindow.this.processList.detailsSelected();
100 }
101 });
102
103 final JButton stop = new JButton("Stop");
104 stop.addActionListener(new ActionListener() {
105 public void actionPerformed(final ActionEvent actionEvent) {
106 ProcessWindow.this.processList.stopSelected();
107 }
108 });
109
110 final JButton refresh = new JButton("Refresh");
111 refresh.addActionListener(new ActionListener() {
112 public void actionPerformed(final ActionEvent actionEvent) {
113 ProcessWindow.this.processList.updateView();
114 }
115 });
116
117
118 final JButton ok = new JButton("OK");
119 ok.addActionListener(new ActionListener() {
120 public void actionPerformed(final ActionEvent actionEvent) {
121 ProcessWindow.this.dispose();
122 }
123 });
124
125 final JButton cancel = new JButton("Cancel");
126 cancel.addActionListener(new ActionListener() {
127 public void actionPerformed(final ActionEvent actionEvent) {
128 ProcessWindow.this.dispose();
129 }
130 });
131
132 final JToggleButton onlyRunning = new JToggleButton("Only Running", true);
133 onlyRunning.addActionListener(new ActionListener() {
134 public void actionPerformed(final ActionEvent actionEvent) {
135 ProcessWindow.this.processList.setRunningOnly(onlyRunning.isSelected());
136 ProcessWindow.this.processList.refreshStates();
137 }
138 });
139
140 bbuilder.addGridded(onlyRunning);
141 bbuilder.addRelatedGap();
142 if (stackTrace != null) {
143 bbuilder.addGriddedButtons(new JButton[]{stackTrace, details, stop, refresh, cancel, ok});
144 } else {
145 bbuilder.addGriddedButtons(new JButton[]{details, stop, refresh, cancel, ok});
146 }
147
148 final JPanel buttons = bbuilder.getPanel();
149 content.add(GuiHelper.addSpaceAndAlignRight(buttons));
150
151 // let the container calculate the ideal size
152 pack();
153
154 final Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
155 setBounds((screenSize.width - getWidth()) / 2, (screenSize.height - getHeight()) / 2,
156 1000, 400);
157 }
158
159 /**
160 * Update from model.
161 */
162 public void updateView() {
163 invalidate();
164 repaint();
165 }
166
167
168 }
|