Make the toolbar be singleton and initialized once.

Solves TSK-564 	Toolbar widgets sometimes disabled
This commit is contained in:
adam-m 2012-08-29 16:54:25 -04:00
parent c78462d6a4
commit e8d16d5588
3 changed files with 34 additions and 29 deletions

View File

@ -16,17 +16,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.ingest;
import java.awt.Component;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import org.openide.util.actions.Presenter;
import org.openide.windows.Mode;
import org.openide.windows.WindowManager;
//@ActionID(category = "File",
//id = "org.sleuthkit.autopsy.ingest.IngestMessagesAction")
@ -36,15 +31,14 @@ import org.openide.windows.WindowManager;
// @ActionReference(path = "Toolbars/File", position = 575)
//})
//@Messages("CTL_IngestMessagesAction=Messages")
public final class IngestMessagesAction extends AbstractAction implements Presenter.Toolbar {
public final class IngestMessagesAction extends AbstractAction implements Presenter.Toolbar {
@Override
public void actionPerformed(ActionEvent e) {
}
@Override
public Component getToolbarPresenter() {
return new IngestMessagesToolbar();
return IngestMessagesToolbar.getDefault();
}
}

View File

@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>

View File

@ -32,22 +32,35 @@ import org.sleuthkit.autopsy.casemodule.Case;
/**
* Toolbar for Ingest
*
*
*/
public class IngestMessagesToolbar extends javax.swing.JPanel {
private IngestMessagesButton ingestMessagesButton = new IngestMessagesButton();
private static IngestMessagesToolbar instance;
/** Creates new form IngestMessagesToolbar */
public IngestMessagesToolbar() {
/**
* Creates new form IngestMessagesToolbar
*/
private IngestMessagesToolbar() {
initComponents();
customizeComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
/**
* @return the default instance IngestMessagesToolbar
*/
public static IngestMessagesToolbar getDefault() {
if (instance == null) {
instance = new IngestMessagesToolbar();
}
return instance;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@ -82,7 +95,6 @@ public class IngestMessagesToolbar extends javax.swing.JPanel {
ingestMessagesButton.setMinimumSize(new java.awt.Dimension(38, 24));
ingestMessagesButton.setPreferredSize(new java.awt.Dimension(38, 24));
ingestMessagesButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
showIngestMessages();
@ -94,11 +106,10 @@ public class IngestMessagesToolbar extends javax.swing.JPanel {
private void customizeComponents() {
customizeButton();
this.setBorder(null);
IngestMessagePanel.addPropertyChangeSupportListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
final int numberMessages = (Integer) evt.getNewValue();
@ -110,7 +121,6 @@ public class IngestMessagesToolbar extends javax.swing.JPanel {
});
Case.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(Case.CASE_CURRENT_CASE)) {
@ -140,31 +150,32 @@ public class IngestMessagesToolbar extends javax.swing.JPanel {
private static class IngestMessagesButton extends JButton {
private static final int fontSize = 9;
private static final Font messagesFont = new java.awt.Font("Tahoma", Font.PLAIN, fontSize);
private int messages = 0;
@Override
public void paint(Graphics g) {
public void paint(Graphics g) {
super.paint(g);
if (messages == 0)
if (messages == 0) {
return;
}
//paint text
String messageStr = Integer.toString(messages);
final int len = messageStr.length();
g.setFont(messagesFont);
int dx = len * 5 + 5;
int x = getSize().width - dx;
if (x<0)
if (x < 0) {
x = 0;
}
g.setColor(Color.GRAY);
//g.fillRect(x, 1, dx, fontSize);
g.fillRoundRect(x, 1, dx, fontSize, 2, 2);
g.setColor(Color.WHITE);
g.drawString(messageStr, x+2, fontSize);
g.drawString(messageStr, x + 2, fontSize);
}
void setMessages(int messages) {