ProcessWindow.java
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 
028 import org.qedeq.base.trace.Trace;
029 import org.qedeq.base.utility.YodaUtility;
030 import org.qedeq.gui.se.util.GuiHelper;
031 
032 import com.jgoodies.forms.builder.ButtonBarBuilder;
033 
034 /**
035  * Configures the application.
036  *
037  @author  Michael Meyling
038  */
039 
040 public class ProcessWindow extends JFrame {
041 
042     /** This class. */
043     private static final Class CLASS = ProcessWindow.class;
044 
045     /** Here is our process list. */
046     private ProcessListPane processList;
047 
048     /**
049      * Creates new Panel.
050      */
051     public ProcessWindow() {
052         super("Processes");
053         final String method = "Constructor";
054         Trace.begin(CLASS, this, method);
055         try {
056             setDefaultCloseOperation(DISPOSE_ON_CLOSE);
057             setupView();
058             updateView();
059         catch (Throwable e) {
060             Trace.fatal(CLASS, this, "Initalization of PreferencesDialog failed.", method, e);
061         finally {
062             Trace.end(CLASS, this, method);
063         }
064     }
065 
066 
067     /**
068      * Assembles the GUI components of the panel.
069      */
070     public final void setupView() {
071         setIconImage(GuiHelper.readImageIcon("tango/16x16/categories/applications-system.png")
072             .getImage());
073         final Container content = getContentPane();
074         content.setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
075         JPanel allOptions = new JPanel();
076         allOptions.setBorder(GuiHelper.getEmptyBorder());
077         allOptions.setLayout(new BoxLayout(allOptions, BoxLayout.Y_AXIS));
078         processList = new ProcessListPane();
079         allOptions.add(processList);
080         content.add(allOptions);
081 
082         ButtonBarBuilder bbuilder = ButtonBarBuilder.createLeftToRightBuilder();
083 
084         JButton stackTrace = null;
085 
086         if (YodaUtility.existsMethod(Thread.class, "getStackTrace"new Class[] {})) {
087             stackTrace = new JButton("Stacktrace");
088             stackTrace.addActionListener(new  ActionListener() {
089                 public void actionPerformed(final ActionEvent actionEvent) {
090                     ProcessWindow.this.processList.stackTraceSelected();
091                 }
092             });
093         }
094 
095         JButton stop = new JButton("Stop");
096         stop.addActionListener(new  ActionListener() {
097             public void actionPerformed(final ActionEvent actionEvent) {
098                 ProcessWindow.this.processList.stopSelected();
099             }
100         });
101 
102 
103         JButton refresh = new JButton("Refresh");
104         refresh.addActionListener(new  ActionListener() {
105             public void actionPerformed(final ActionEvent actionEvent) {
106                 ProcessWindow.this.processList.updateView();
107             }
108         });
109 
110 
111         JButton ok = new JButton("OK");
112         ok.addActionListener(new  ActionListener() {
113             public void actionPerformed(final ActionEvent actionEvent) {
114                 ProcessWindow.this.dispose();
115             }
116         });
117 
118         JButton cancel = new JButton("Cancel");
119         cancel.addActionListener(new  ActionListener() {
120             public void actionPerformed(final ActionEvent actionEvent) {
121                 ProcessWindow.this.dispose();
122             }
123         });
124 
125         if (stackTrace != null) {
126             bbuilder.addGriddedButtons(new JButton[]{stackTrace, stop, refresh, cancel, ok});
127         else {
128             bbuilder.addGriddedButtons(new JButton[]{stop, refresh, cancel, ok});
129         }
130 
131         final JPanel buttons = bbuilder.getPanel();
132         content.add(GuiHelper.addSpaceAndAlignRight(buttons));
133 
134         // let the container calculate the ideal size
135         pack();
136 
137         final Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
138         setBounds((screenSize.width - getWidth()) 2(screenSize.height - getHeight()) 2,
139             1000400);
140     }
141 
142     /**
143      * Update from model.
144      */
145     public void updateView() {
146         invalidate();
147         repaint();
148     }
149 
150 
151 }