001: /*
002: * ProgressPanel.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.dbobjects;
013:
014: import java.awt.Dimension;
015: import java.awt.FontMetrics;
016: import java.awt.Window;
017: import java.io.File;
018: import javax.swing.SwingUtilities;
019:
020: import workbench.gui.components.WbButton;
021: import workbench.interfaces.Interruptable;
022: import workbench.resource.ResourceMgr;
023: import workbench.storage.RowActionMonitor;
024:
025: /**
026: *
027: * @author support@sql-workbench.net
028: */
029: public class ProgressPanel extends javax.swing.JPanel implements
030: RowActionMonitor {
031:
032: private Interruptable spooler;
033:
034: /** Creates new form SpoolerProgress */
035: public ProgressPanel(Interruptable aWorker) {
036: this .spooler = aWorker;
037: initComponents();
038: }
039:
040: public void setRowInfo(long aRow) {
041: this .rowInfo.setText(Long.toString(aRow));
042: }
043:
044: public void setRowInfo(String info) {
045: this .rowInfo.setText(info);
046: }
047:
048: public void setInfoText(String aText) {
049: this .progressInfoText.setText(aText);
050: }
051:
052: public void setFilename(String aFilename) {
053: File f = new File(aFilename);
054: String fullName = f.getAbsolutePath();
055: this .fileNameField.setToolTipText(fullName);
056: this .fileNameField.setText(fullName);
057: FontMetrics fm = this .getFontMetrics(this .fileNameField
058: .getFont());
059: int w = fm.stringWidth(aFilename) + 10;
060: int h = fm.getHeight() + 2;
061: Dimension d = new Dimension(w, h < 22 ? 22 : h);
062: fileNameField.setPreferredSize(d);
063: fileNameField.setMinimumSize(d);
064: this .invalidate();
065: }
066:
067: public void setRowSize(int cols) {
068: FontMetrics fm = this .getFontMetrics(this .getFont());
069: int w = fm.charWidth(' ');
070: int h = fm.getHeight() + 2;
071: Dimension d = new Dimension(w * cols, h < 22 ? 22 : h);
072: this .rowInfo.setPreferredSize(d);
073: this .rowInfo.setMinimumSize(d);
074: this .invalidate();
075: }
076:
077: public void setInfoSize(int cols) {
078: this .progressInfoText.setColumns(cols);
079: this .doLayout();
080: this .updateUI();
081: }
082:
083: public void jobFinished() {
084: }
085:
086: public void setCurrentObject(String object, long number,
087: long totalObjects) {
088: }
089:
090: public void setCurrentRow(long currentRow, long totalRows) {
091: if (currentRow > -1)
092: this .rowInfo.setText(Long.toString(currentRow));
093: }
094:
095: public void saveCurrentType(String type) {
096: }
097:
098: public void restoreType(String type) {
099: }
100:
101: public void setMonitorType(int aType) {
102: }
103:
104: public int getMonitorType() {
105: return RowActionMonitor.MONITOR_PLAIN;
106: }
107:
108: /** This method is called from within the constructor to
109: * initialize the form.
110: * WARNING: Do NOT modify this code. The content of this method is
111: * always regenerated by the Form Editor.
112: */
113: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
114: private void initComponents() {
115: java.awt.GridBagConstraints gridBagConstraints;
116:
117: fileNameField = new javax.swing.JTextField();
118: infoPanel = new javax.swing.JPanel();
119: progressInfoText = new javax.swing.JTextField();
120: rowInfo = new javax.swing.JLabel();
121: cancelButton = new WbButton();
122:
123: setLayout(new java.awt.GridBagLayout());
124:
125: fileNameField.setEditable(false);
126: fileNameField.setBorder(new javax.swing.border.CompoundBorder(
127: new javax.swing.border.EtchedBorder(),
128: new javax.swing.border.EmptyBorder(new java.awt.Insets(
129: 2, 2, 2, 2))));
130: fileNameField.setDisabledTextColor(java.awt.Color.black);
131: fileNameField.setMargin(new java.awt.Insets(0, 2, 0, 0));
132: gridBagConstraints = new java.awt.GridBagConstraints();
133: gridBagConstraints.gridx = 0;
134: gridBagConstraints.gridy = 1;
135: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 6);
137: add(fileNameField, gridBagConstraints);
138:
139: infoPanel.setLayout(new java.awt.BorderLayout(0, 5));
140:
141: infoPanel.setBorder(new javax.swing.border.CompoundBorder(
142: new javax.swing.border.EtchedBorder(),
143: new javax.swing.border.EmptyBorder(new java.awt.Insets(
144: 2, 2, 2, 2))));
145: progressInfoText.setColumns(10);
146: progressInfoText.setEditable(false);
147: progressInfoText.setBorder(null);
148: progressInfoText.setDisabledTextColor(java.awt.Color.black);
149: infoPanel.add(progressInfoText, java.awt.BorderLayout.CENTER);
150:
151: rowInfo
152: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
153: rowInfo.setMaximumSize(new java.awt.Dimension(32768, 18));
154: rowInfo.setMinimumSize(new java.awt.Dimension(30, 18));
155: rowInfo.setPreferredSize(new java.awt.Dimension(50, 18));
156: infoPanel.add(rowInfo, java.awt.BorderLayout.EAST);
157:
158: gridBagConstraints = new java.awt.GridBagConstraints();
159: gridBagConstraints.gridx = 0;
160: gridBagConstraints.gridy = 0;
161: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
162: gridBagConstraints.weightx = 1.0;
163: gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 6);
164: add(infoPanel, gridBagConstraints);
165:
166: cancelButton.setText(ResourceMgr.getString("LblCancel"));
167: cancelButton
168: .addActionListener(new java.awt.event.ActionListener() {
169: public void actionPerformed(
170: java.awt.event.ActionEvent evt) {
171: cancelButtonActionPerformed(evt);
172: }
173: });
174:
175: gridBagConstraints = new java.awt.GridBagConstraints();
176: gridBagConstraints.gridx = 0;
177: gridBagConstraints.gridy = 2;
178: gridBagConstraints.weighty = 1.0;
179: gridBagConstraints.insets = new java.awt.Insets(12, 0, 4, 0);
180: add(cancelButton, gridBagConstraints);
181:
182: }
183:
184: // </editor-fold>//GEN-END:initComponents
185:
186: private void cancelButtonActionPerformed(
187: java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelButtonActionPerformed
188: {//GEN-HEADEREND:event_cancelButtonActionPerformed
189: if (this .spooler != null) {
190: if (this .spooler.confirmCancel())
191: this .spooler.cancelExecution();
192: }
193: }//GEN-LAST:event_cancelButtonActionPerformed
194:
195: // Variables declaration - do not modify//GEN-BEGIN:variables
196: private javax.swing.JButton cancelButton;
197: private javax.swing.JTextField fileNameField;
198: private javax.swing.JPanel infoPanel;
199: private javax.swing.JTextField progressInfoText;
200: private javax.swing.JLabel rowInfo;
201: // End of variables declaration//GEN-END:variables
202:
203: }
|