001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2006, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library 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 GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.gui2;
021:
022: import java.awt.BorderLayout;
023: import java.awt.GridLayout;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.WindowAdapter;
026: import java.awt.event.WindowEvent;
027:
028: import javax.swing.AbstractAction;
029: import javax.swing.JButton;
030: import javax.swing.JLabel;
031: import javax.swing.JOptionPane;
032: import javax.swing.JPanel;
033: import javax.swing.JTextField;
034: import javax.swing.WindowConstants;
035:
036: /**
037: * This is the properties dialog of the GUI. It allows the user to set the
038: * size of the tabs and font size. If the user changes the font size they
039: * will be told to restart the computer before the new size takes affect.
040: * @author Kristin Stephens
041: */
042: public class PropertiesDialog extends FBDialog {
043: private static PropertiesDialog instance;
044: private JTextField tabTextField;
045: private JTextField fontTextField;
046:
047: public static PropertiesDialog getInstance() {
048: if (instance == null)
049: instance = new PropertiesDialog();
050: return instance;
051: }
052:
053: private PropertiesDialog() {
054: JPanel contentPanel = new JPanel(new BorderLayout());
055: JPanel mainPanel = new JPanel();
056: mainPanel.setLayout(new GridLayout(2, 2));
057: mainPanel.add(new JLabel("Tab Size"));
058: tabTextField = new JTextField(Integer.toString(GUISaveState
059: .getInstance().getTabSize()));
060: mainPanel.add(tabTextField);
061:
062: mainPanel.add(new JLabel("Font Size"));
063: fontTextField = new JTextField(Float.toString(GUISaveState
064: .getInstance().getFontSize()));
065: mainPanel.add(fontTextField);
066:
067: contentPanel.add(mainPanel, BorderLayout.CENTER);
068:
069: JPanel bottomPanel = new JPanel();
070: bottomPanel.add(new JButton(new AbstractAction("Apply") {
071: public void actionPerformed(ActionEvent evt) {
072: if (Integer.decode(tabTextField.getText()).intValue() != GUISaveState
073: .getInstance().getTabSize()) {
074: GUISaveState.getInstance().setTabSize(
075: Integer.decode(tabTextField.getText())
076: .intValue());
077: MainFrame.getInstance().displayer.clearCache();
078: MainFrame.getInstance().syncBugInformation(); //This causes the GUI to redisplay the current code
079: }
080:
081: if (Float.parseFloat(fontTextField.getText()) != GUISaveState
082: .getInstance().getFontSize()) {
083: GUISaveState.getInstance().setFontSize(
084: Float.parseFloat(fontTextField.getText()));
085: JOptionPane
086: .showMessageDialog(
087: PropertiesDialog.getInstance(),
088: "To implement the new font size, please restart FindBugs.",
089: "Changing Font",
090: JOptionPane.INFORMATION_MESSAGE);
091: }
092: }
093: }));
094:
095: bottomPanel.add(new JButton(new AbstractAction("Reset") {
096: public void actionPerformed(ActionEvent evt) {
097: tabTextField.setText(Integer.toString(GUISaveState
098: .getInstance().getTabSize()));
099: fontTextField.setText(Float.toString(GUISaveState
100: .getInstance().getFontSize()));
101: }
102: }));
103:
104: contentPanel.add(bottomPanel, BorderLayout.SOUTH);
105: setContentPane(contentPanel);
106: setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
107: setModal(true);
108: pack();
109:
110: addWindowListener(new WindowAdapter() {
111: @Override
112: public void windowDeactivated(WindowEvent e) {
113: if (Integer.decode(tabTextField.getText()).intValue() != GUISaveState
114: .getInstance().getTabSize())
115: tabTextField.setText(Integer.toString(GUISaveState
116: .getInstance().getTabSize()));
117:
118: if (Float.parseFloat(fontTextField.getText()) != GUISaveState
119: .getInstance().getFontSize()) {
120: fontTextField.setText(Float.toString(GUISaveState
121: .getInstance().getFontSize()));
122: }
123: }
124: });
125: }
126: }
|