Subversion Repositories public

Rev

Rev 87 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 87 Rev 89
Line 1... Line 1...
1
/*
1
/*
2
 * TaskFrame.java - implementation of LWTT main application window
2
 * TaskFrame.java - implementation of LWTT main application window
3
 *
3
 *
4
 * Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz
4
 * Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
5
 *
5
 *
6
 * ==========================================================================
6
 * ==========================================================================
7
 *
7
 *
8
 * This program is free software; you can redistribute it and/or modify
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License Version 2 as
9
 * it under the terms of the GNU General Public License Version 2 as
Line 21... Line 21...
21
 * ==========================================================================
21
 * ==========================================================================
22
 */
22
 */
23
23
24
package cz.aiken.util.lwtt;
24
package cz.aiken.util.lwtt;
25
25
-
 
26
import java.util.*;
26
import java.awt.*;
27
import java.awt.*;
27
import javax.swing.*;
28
import javax.swing.*;
28
import javax.swing.table.*;
29
import javax.swing.table.*;
29
import javax.swing.event.*;
30
import javax.swing.event.*;
30
31
31
/**
32
/**
32
 * This class represents the main application frame.
33
 * This class represents the main application frame.
33
 * @author luk
34
 * @author luk
34
 */
35
 */
35
public class TaskFrame extends javax.swing.JFrame implements ListSelectionListener {
36
public class TaskFrame extends JFrame implements ListSelectionListener {
36
   
37
   
37
    private TaskTableModel model = new TaskTableModel();
38
    private TaskTableModel model = null;
-
 
39
   
-
 
40
    private Properties startSettings = null;
38
   
41
   
39
    /**
42
    /**
40
     * Time consumption column width
43
     * Time consumption column width
41
     */
44
     */
42
    public static final int CONS_COL_WIDTH = 180;
45
    public static final int CONS_COL_WIDTH = 180;
43
   
46
   
44
    /**
47
    /**
45
     * Creates new form TaskFrame
48
     * Creates new form TaskFrame
46
     */
49
     */
47
    public TaskFrame() {
50
    public TaskFrame() {
-
 
51
        model = new TaskTableModel(this);
48
        initComponents();
52
        initComponents();
49
        TableColumn tc = jTable1.getColumnModel().getColumn(1);
53
        TableColumn tc = jTable1.getColumnModel().getColumn(1);
50
        tc.setMaxWidth(CONS_COL_WIDTH);
54
        tc.setMaxWidth(CONS_COL_WIDTH);
51
        tc.setPreferredWidth(CONS_COL_WIDTH);
55
        tc.setPreferredWidth(CONS_COL_WIDTH);
52
        jTable1.getSelectionModel().addListSelectionListener(this);
56
        jTable1.getSelectionModel().addListSelectionListener(this);
53
        updateButtons();
57
        updateButtons();
-
 
58
       
-
 
59
        try {
-
 
60
            String xs = startSettings.getProperty("window.location.x");
-
 
61
            String ys = startSettings.getProperty("window.location.y");
-
 
62
            if (xs != null && ys != null) {
-
 
63
                setLocation(Integer.parseInt(xs), Integer.parseInt(ys));
-
 
64
            }
-
 
65
        } catch (NumberFormatException e) {
-
 
66
            JOptionPane.showMessageDialog(null, "Cannot load window location (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
-
 
67
        }
-
 
68
       
-
 
69
        try {
-
 
70
            String ws = startSettings.getProperty("window.size.w");
-
 
71
            String hs = startSettings.getProperty("window.size.h");
-
 
72
            if (ws != null && hs != null) {
-
 
73
                setSize(Integer.parseInt(ws), Integer.parseInt(hs));
-
 
74
            }
-
 
75
        } catch (NumberFormatException e) {
-
 
76
            JOptionPane.showMessageDialog(null, "Cannot load window size (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
-
 
77
        }
54
    }
78
    }
55
   
79
   
-
 
80
   
-
 
81
    /**
-
 
82
     * Sets initial (start) settings.
-
 
83
     * @param props properties with initial settings
-
 
84
     */
-
 
85
    public void setStartSettings(Properties props) {
-
 
86
        startSettings = props;
-
 
87
    }
-
 
88
   
-
 
89
    /**
-
 
90
     * Updates the buttons' state.
-
 
91
     */
56
    void updateButtons() {
92
    private void updateButtons() {
57
        int cnt = jTable1.getSelectedRowCount();
93
        int cnt = jTable1.getSelectedRowCount();
58
        if (cnt == 0) {
94
        if (cnt == 0) {
59
            startButton.setEnabled(false);
95
            startButton.setEnabled(false);
60
            stopButton.setEnabled(false);
96
            stopButton.setEnabled(false);
61
            removeButton.setEnabled(false);
97
            removeButton.setEnabled(false);
-
 
98
            resetButton.setEnabled(false);
62
        }
99
        }
63
        else {
100
        else {
64
            int start = jTable1.getSelectedRow();
101
            int start = jTable1.getSelectedRow();
65
            int end = start + cnt - 1;
102
            int end = start + cnt - 1;
66
            removeButton.setEnabled(true);
103
            removeButton.setEnabled(true);
-
 
104
            resetButton.setEnabled(true);
67
           
105
           
68
            int rcnt = 0;
106
            int rcnt = 0;
69
            for (int i=start; i<=end; i++) {
107
            for (int i=start; i<=end; i++) {
70
                if (model.isRunning(i))
108
                if (model.isRunning(i))
71
                    rcnt++;
109
                    rcnt++;
Line 86... Line 124...
86
    /** This method is called from within the constructor to
124
    /** This method is called from within the constructor to
87
     * initialize the form.
125
     * initialize the form.
88
     * WARNING: Do NOT modify this code. The content of this method is
126
     * WARNING: Do NOT modify this code. The content of this method is
89
     * always regenerated by the Form Editor.
127
     * always regenerated by the Form Editor.
90
     */
128
     */
91
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
129
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
92
    private void initComponents() {
130
    private void initComponents() {
-
 
131
93
        jSplitPane1 = new javax.swing.JSplitPane();
132
        jSplitPane1 = new javax.swing.JSplitPane();
94
        jPanel1 = new javax.swing.JPanel();
133
        jPanel1 = new javax.swing.JPanel();
95
        startButton = new javax.swing.JButton();
134
        startButton = new javax.swing.JButton();
96
        stopButton = new javax.swing.JButton();
135
        stopButton = new javax.swing.JButton();
97
        addButton = new javax.swing.JButton();
136
        addButton = new javax.swing.JButton();
98
        removeButton = new javax.swing.JButton();
137
        removeButton = new javax.swing.JButton();
-
 
138
        resetButton = new javax.swing.JButton();
99
        jScrollPane1 = new javax.swing.JScrollPane();
139
        jScrollPane1 = new javax.swing.JScrollPane();
100
        jTable1 = new javax.swing.JTable();
140
        jTable1 = new javax.swing.JTable();
101
141
102
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
142
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
103
        setTitle("LWTT");
143
        setTitle("LWTT");
Line 106... Line 146...
106
                TaskFrame.this.windowClosing(evt);
146
                TaskFrame.this.windowClosing(evt);
107
            }
147
            }
108
        });
148
        });
109
149
110
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
150
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
-
 
151
111
        jPanel1.setMinimumSize(new java.awt.Dimension(10, 25));
152
        jPanel1.setMinimumSize(new java.awt.Dimension(10, 25));
-
 
153
112
        startButton.setText("Start");
154
        startButton.setText("Start");
113
        startButton.addActionListener(new java.awt.event.ActionListener() {
155
        startButton.addActionListener(new java.awt.event.ActionListener() {
114
            public void actionPerformed(java.awt.event.ActionEvent evt) {
156
            public void actionPerformed(java.awt.event.ActionEvent evt) {
115
                startPressed(evt);
157
                startPressed(evt);
116
            }
158
            }
Line 135... Line 177...
135
            public void actionPerformed(java.awt.event.ActionEvent evt) {
177
            public void actionPerformed(java.awt.event.ActionEvent evt) {
136
                removePressed(evt);
178
                removePressed(evt);
137
            }
179
            }
138
        });
180
        });
139
181
-
 
182
        resetButton.setText("Reset");
-
 
183
        resetButton.addActionListener(new java.awt.event.ActionListener() {
-
 
184
            public void actionPerformed(java.awt.event.ActionEvent evt) {
-
 
185
                resetPressed(evt);
-
 
186
            }
-
 
187
        });
-
 
188
140
        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
189
        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
141
        jPanel1.setLayout(jPanel1Layout);
190
        jPanel1.setLayout(jPanel1Layout);
142
        jPanel1Layout.setHorizontalGroup(
191
        jPanel1Layout.setHorizontalGroup(
143
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
192
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
144
            .add(jPanel1Layout.createSequentialGroup()
193
            .add(jPanel1Layout.createSequentialGroup()
Line 147... Line 196...
147
                .add(stopButton)
196
                .add(stopButton)
148
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
197
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
149
                .add(addButton)
198
                .add(addButton)
150
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
199
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
151
                .add(removeButton)
200
                .add(removeButton)
-
 
201
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-
 
202
                .add(resetButton)
152
                .addContainerGap(310, Short.MAX_VALUE))
203
                .addContainerGap(251, Short.MAX_VALUE))
153
        );
204
        );
154
        jPanel1Layout.setVerticalGroup(
205
        jPanel1Layout.setVerticalGroup(
155
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
206
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
156
            .add(org.jdesktop.layout.GroupLayout.BASELINE, startButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
207
            .add(startButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
157
            .add(org.jdesktop.layout.GroupLayout.BASELINE, stopButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
208
            .add(stopButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
158
            .add(org.jdesktop.layout.GroupLayout.BASELINE, addButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
209
            .add(addButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
159
            .add(org.jdesktop.layout.GroupLayout.BASELINE, removeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
210
            .add(removeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
-
 
211
            .add(resetButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
160
        );
212
        );
-
 
213
161
        jSplitPane1.setTopComponent(jPanel1);
214
        jSplitPane1.setTopComponent(jPanel1);
162
215
163
        jScrollPane1.setPreferredSize(new java.awt.Dimension(454, 400));
216
        jScrollPane1.setPreferredSize(new java.awt.Dimension(454, 400));
164
        jScrollPane1.setVerifyInputWhenFocusTarget(false);
217
        jScrollPane1.setVerifyInputWhenFocusTarget(false);
165
        jScrollPane1.setViewport(null);
-
 
-
 
218
166
        jTable1.setModel(model);
219
        jTable1.setModel(model);
167
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
220
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
168
        jTable1.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
221
        jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {
169
            private Color fg = Color.RED;
222
            private Color fg = Color.RED;
170
            private Color bg = new Color(255, 240, 240);
223
            private Color bg = new Color(255, 240, 240);
171
224
172
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
225
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
173
                Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
226
                Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
-
 
227
174
                if (JLabel.class.isAssignableFrom(c.getClass())) {
228
                if (JLabel.class.isAssignableFrom(c.getClass())) {
175
                    ((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);
229
                    ((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);
176
                }
230
                }
177
231
178
                if (model.isRunning(row)) {
232
                if (model.isRunning(row)) {
Line 201... Line 255...
201
        );
255
        );
202
        layout.setVerticalGroup(
256
        layout.setVerticalGroup(
203
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
257
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
204
            .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
258
            .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
205
        );
259
        );
-
 
260
206
        pack();
261
        pack();
207
    }// </editor-fold>//GEN-END:initComponents
262
    }// </editor-fold>//GEN-END:initComponents
208
263
-
 
264
    private void resetPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetPressed
-
 
265
        int start = jTable1.getSelectedRow();
-
 
266
        int cnt = jTable1.getSelectedRowCount();
-
 
267
        if (cnt > 0)
-
 
268
            model.resetTasks(start, start + cnt - 1);
-
 
269
    }//GEN-LAST:event_resetPressed
-
 
270
209
    private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
271
    private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
210
        model.stopAllTasks();
272
        model.stopAllTasks();
211
        model.saveToFile();
273
        model.saveToFile();
212
    }//GEN-LAST:event_windowClosing
274
    }//GEN-LAST:event_windowClosing
213
275
Line 246... Line 308...
246
    private javax.swing.JPanel jPanel1;
308
    private javax.swing.JPanel jPanel1;
247
    private javax.swing.JScrollPane jScrollPane1;
309
    private javax.swing.JScrollPane jScrollPane1;
248
    private javax.swing.JSplitPane jSplitPane1;
310
    private javax.swing.JSplitPane jSplitPane1;
249
    private javax.swing.JTable jTable1;
311
    private javax.swing.JTable jTable1;
250
    private javax.swing.JButton removeButton;
312
    private javax.swing.JButton removeButton;
-
 
313
    private javax.swing.JButton resetButton;
251
    private javax.swing.JButton startButton;
314
    private javax.swing.JButton startButton;
252
    private javax.swing.JButton stopButton;
315
    private javax.swing.JButton stopButton;
253
    // End of variables declaration//GEN-END:variables
316
    // End of variables declaration//GEN-END:variables
254
   
317
   
255
}
318
}