001: /*
002: * Copyright (C) 2004 Giuseppe MANNA
003: *
004: * This file is part of FreeReportBuilder
005: *
006: * FreeReportBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package it.frb;
023:
024: import it.frb.admin.*;
025: import java.awt.*;
026: import java.awt.event.*;
027: import java.io.*;
028: import javax.swing.*;
029:
030: public class OptionsDialog extends JDialog {
031: public final static int ACCEPTED = JOptionPane.OK_OPTION;
032: public final static int CANCELLED = JOptionPane.CANCEL_OPTION;
033:
034: protected JPanel pnlButtons = new JPanel(new FlowLayout(
035: FlowLayout.RIGHT, 9, 0));
036: protected JButton btnOk = new JButton("Ok");
037: protected JButton btnCancel = new JButton("Cancel");
038: protected JComboBox cmbConnProfile;
039: protected JComboBox cmbLookAndFeel;
040: //protected JSpinner spnFontSize;
041: protected JCheckBox chkUseResultSet;
042: protected JCheckBox chkUseMultiTransaction;
043:
044: public int nClosedOption = CANCELLED;
045:
046: public OptionsDialog() {
047: setTitle("Options");
048:
049: setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
050:
051: getContentPane().setLayout(new BorderLayout());
052:
053: if (getContentPane() instanceof JPanel)
054: ((JPanel) getContentPane()).setBorder(BorderFactory
055: .createEmptyBorder(9, 9, 9, 9));
056:
057: initButtonPanel();
058: init();
059: pack();
060: }
061:
062: private void init() {
063: /*
064: String[] connName = new String[ UserSession.listProfile().length + 1 ];
065:
066: connName[0] = "None";
067:
068: for( int n = 0; n < UserSession.listProfile().length; n++ )
069: {
070: String fileName = (String)UserSession.listProfile()[n];
071: fileName = fileName.substring( 0, fileName.lastIndexOf( '.' ) );
072:
073: connName[n+1] = fileName;
074: }
075:
076: String connNone = ConfigurationProperties.properties().getStartupUPC("None");
077:
078: if( connNone.endsWith( ConfigurationProperties.KEY_CONNECTION_FILE_EXT) )
079: {
080: connNone = connNone.substring( 0, connNone.lastIndexOf( '.' ) );
081: }
082:
083: this.cmbConnProfile = new JComboBox(connName);
084: this.cmbConnProfile.setSelectedItem(connNone);
085: */
086: JPanel pnl = new JPanel(new java.awt.GridLayout(5, 2, 5, 8));
087: pnl.setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
088:
089: //pnl.add(new JLabel("Set connection name: "));
090: //pnl.add(this.cmbConnProfile);
091:
092: UIManager.LookAndFeelInfo[] lafInfo = UIManager
093: .getInstalledLookAndFeels();
094: String[] sLookAndFeel = new String[lafInfo.length + 1];
095: sLookAndFeel[0] = "OS native";
096:
097: for (int n = 0; n < lafInfo.length; n++) {
098: sLookAndFeel[n + 1] = lafInfo[n].getName();
099: }
100:
101: String lookAndFeel = ConfigurationProperties.properties()
102: .getLookAndFeel(
103: "javax.swing.plaf.metal.MetalLookAndFeel");
104: int index = (lookAndFeel.length() == 0) ? 0
105: : ConfigurationProperties.indexOf(sLookAndFeel,
106: lookAndFeel, true);
107:
108: this .cmbLookAndFeel = new JComboBox(sLookAndFeel);
109: this .cmbLookAndFeel.setSelectedIndex(Math.max(index, 0));
110:
111: int nSize = ConfigurationProperties.properties()
112: .getFontSize(11);
113: //this.spnFontSize = new JSpinner( new SpinnerNumberModel( nSize, 7, 24, 1 ) );
114:
115: this .chkUseResultSet = new JCheckBox("Use ResultSet",
116: ConfigurationProperties.properties().getUseResultSet(
117: true));
118: this .chkUseMultiTransaction = new JCheckBox(
119: "Use MultiTransaction (re-start application)",
120: ConfigurationProperties.properties()
121: .getUseMultiTransaction(false));
122:
123: pnl.add(new JLabel("Look and Feel"));
124: pnl.add(this .cmbLookAndFeel);
125:
126: //pnl.add( new JLabel( "Default font size" ) );
127: //pnl.add( this.spnFontSize );
128:
129: pnl.add(this .chkUseResultSet);
130: pnl.add(new JLabel()); // Trick to have pair number of components
131:
132: pnl.add(this .chkUseMultiTransaction);
133: pnl.add(new JLabel()); // Trick to have pair number of components
134:
135: getContentPane().setLayout(new java.awt.BorderLayout());
136: getContentPane().add(pnl, java.awt.BorderLayout.NORTH);
137: getContentPane().add(pnlButtons, java.awt.BorderLayout.SOUTH);
138: }
139:
140: public void pack(int nWidth, int nHeight) {
141: super .pack();
142:
143: if (nWidth == 0)
144: nWidth = getWidth();
145: else if (nWidth < 0)
146: nWidth = Math.max(getWidth(), nWidth * -1);
147: else
148: nWidth = Math.min(getWidth(), nWidth);
149:
150: if (nHeight == 0)
151: nHeight = getHeight();
152: else if (nHeight < 0)
153: nHeight = Math.max(getHeight(), nHeight * -1);
154: else
155: nHeight = Math.min(getHeight(), nHeight);
156:
157: setSize(nWidth, nHeight);
158: }
159:
160: private void initButtonPanel() {
161: pnlButtons.setBorder(BorderFactory
162: .createEmptyBorder(9, 0, 0, 0));
163:
164: getRootPane().setDefaultButton(btnOk);
165:
166: pnlButtons.add(btnOk);
167: pnlButtons.add(btnCancel);
168:
169: getContentPane().add(pnlButtons, BorderLayout.SOUTH);
170:
171: btnOk.addActionListener(new ActionListener() {
172: public void actionPerformed(ActionEvent evt) {
173:
174: OptionsDialog.this .save();
175: onAccept(evt);
176: }
177: });
178:
179: btnCancel.addActionListener(new ActionListener() {
180: public void actionPerformed(ActionEvent evt) {
181: onCancel(evt);
182: }
183: });
184: }
185:
186: private void save() {
187: //String connName = (this.cmbConnProfile.getSelectedIndex() == 0) ? "" : this.cmbConnProfile.getSelectedItem()+"";
188: //ConfigurationProperties.properties().setStartupUPC(connName);
189: ConfigurationProperties.properties().setLookAndFeel(
190: (this .cmbLookAndFeel.getSelectedIndex() == 0) ? ""
191: : (String) this .cmbLookAndFeel
192: .getSelectedItem());
193:
194: //Integer intFontSize = (Integer) this.spnFontSize.getValue();
195: //ConfigurationProperties.properties().setFontSize( intFontSize.intValue() );
196:
197: ConfigurationProperties.properties().setUseResultSet(
198: this .chkUseResultSet.isSelected());
199: ConfigurationProperties.properties().setUseMultiTransaction(
200: this .chkUseMultiTransaction.isSelected());
201: }
202:
203: protected void onAccept(ActionEvent evt) {
204: this .nClosedOption = ACCEPTED;
205: this .setVisible(false);
206: }
207:
208: protected void onCancel(ActionEvent evt) {
209: this .nClosedOption = CANCELLED;
210: this .setVisible(false);
211: }
212: }
|