|
/******************************************************************************
Copyright (C) 2006 MakeLogic
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Date : 14th December 2005
Authors : MakeLogic
Design : Ujjwal
Developer : Dharma
********************************************************************************/
package com.makeLogic.utils;
import com.makeLogic.Tail;
import com.makeLogic.TailInternalFrame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import javax.swing.*;
import javax.swing.border.*;
import com.makeLogic.*;
/**
*
* @author dharma
*/
public class ApplicationConstants extends JPanel implements ActionListener
{
Properties appConst;
long ut = 0;
JTextField maxLinesTextField;
JTextField noOfProjToShowTextField;
JTextField maxRecentFilesField;
JCheckBox sendBugInfoCheckBox;
SettingsDialog settingsDialog;
/** Creates a new instance of ApplicationConstants */
public ApplicationConstants(SettingsDialog settingsDialog)
{
//..Set the Border
this.setBorder(new CompoundBorder(new EmptyBorder(5,5,5,5), new TitledBorder("Settings")));
int maxLines = 100;
int noOfProj = 4;
int noOfRecentFiles = 8;
int sendBugInfo = 1;
this.settingsDialog = settingsDialog;
try
{
//..Get the appconst from appconst.ml file
appConst = new Properties();
//..Read the values into properties
appConst.load(new FileInputStream(TailMDI.APP_CONSTANTS_FILE));
//..Read the values
maxLines = Integer.parseInt(appConst.getProperty("maxlines"));
noOfProj = Integer.parseInt(appConst.getProperty("noofproj"));
noOfRecentFiles = Integer.parseInt(appConst.getProperty("maxrecentfiles"));
sendBugInfo = Integer.parseInt(appConst.getProperty("sendbuginfo"));
ut = Long.parseLong(appConst.getProperty("ut"));
}
catch(Exception ex)
{
//..Do Nothing
//Trace.exception(ex);
try
{
//..Create the file
java.io.File createFile = new java.io.File(TailMDI.APP_CONSTANTS_FILE);
createFile.createNewFile();
}
catch(Exception exp)
{
Trace.exception(exp);
}
//..Set the default values
noOfProj = 4;
maxLines = 100;
noOfRecentFiles = 8;
sendBugInfo = 1;
ut = 0;
//..add the properties to the file
appConst.setProperty("maxlines",""+100);
appConst.setProperty("noofproj",""+4);
appConst.setProperty("maxrecentfiles",""+8);
appConst.setProperty("sendbuginfo",""+1);
appConst.setProperty("ut",""+0);
//..Store the Properties into a file.
try
{
appConst.store(new FileOutputStream(TailMDI.APP_CONSTANTS_FILE),null);
}
catch(Exception writeException)
{
//..Do Nothing
Trace.exception(writeException);
}
}
//..Set Grid Layout
setLayout(new GridLayout(5,1));
//..Create Panels
//..Max lines to show
JPanel maxLinesToDisplayPanel = new JPanel();
JLabel maxLinesLabel = new JLabel("Maximum Lines To Display ");
maxLinesTextField = new JTextField(4);
maxLinesTextField.setText(""+maxLines);
//..Add to Panel
maxLinesToDisplayPanel.add(maxLinesLabel);
maxLinesToDisplayPanel.add(maxLinesTextField);
//..number of proj to show
JPanel noOfProjToShowPanel = new JPanel();
JLabel noOfProjToShowLabel = new JLabel("Max Number of Projects To Show ");
noOfProjToShowTextField = new JTextField(2);
noOfProjToShowTextField.setText(""+noOfProj);
//..Add to Panel
noOfProjToShowPanel.add(noOfProjToShowLabel);
noOfProjToShowPanel.add(noOfProjToShowTextField);
//..number of recent file entries to show
JPanel maxRecentPanel = new JPanel();
JLabel maxRecentFilesLabel = new JLabel("Maximum Number of Recent Files ");
maxRecentFilesField = new JTextField(2);
maxRecentFilesField.setText(""+noOfRecentFiles);
//..Add to Panel
maxRecentPanel.add(maxRecentFilesLabel);
maxRecentPanel.add(maxRecentFilesField);
//..Send bug info
JPanel sendBugInfoPanel = new JPanel();
JLabel sendBugInfoLabel = new JLabel("Send Bug Info");
sendBugInfoCheckBox = new JCheckBox();
//..check if value is 1
if(sendBugInfo == 1)
{
sendBugInfoCheckBox.setSelected(true);
}
else
{
sendBugInfoCheckBox.setSelected(false);
}
//..Add to Panel
sendBugInfoPanel.add(sendBugInfoLabel);
sendBugInfoPanel.add(sendBugInfoCheckBox);
//..Add to the main panel
add(maxLinesToDisplayPanel);
add(noOfProjToShowPanel);
add(maxRecentPanel);
//..Debug - Add this in next version
//..add(sendBugInfoPanel);
//..Create Apply Ok Cancel buttons
JButton applyButton = new JButton("Apply");
JButton okButton = new JButton("Ok");
JButton cancelButton = new JButton("Cancel");
JPanel buttonsPanel = new JPanel();
buttonsPanel.add(applyButton);
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
//..Add action listeners
applyButton.addActionListener(this);
okButton.addActionListener(this);
cancelButton.addActionListener(this);
add(buttonsPanel);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand() == "Apply")
{
//..Set the constant variables
TailInternalFrame.MAX_LINES_TO_DISPLAY = Integer.parseInt(maxLinesTextField.getText());
Tail.tailMDI.noOfProjects = Integer.parseInt(noOfProjToShowTextField.getText());
FileMenu.maxEntriesInRecentFilesMenu = Integer.parseInt(maxRecentFilesField.getText());
if(sendBugInfoCheckBox.isSelected())
{
Tail.tailMDI.sendBugInfo = 1;
}
else
{
Tail.tailMDI.sendBugInfo = 0;
}
//..Write to file
appConst.setProperty("maxlines",maxLinesTextField.getText());
appConst.setProperty("noofproj",noOfProjToShowTextField.getText());
appConst.setProperty("maxrecentfiles",maxRecentFilesField.getText());
if(sendBugInfoCheckBox.isSelected())
{
appConst.setProperty("sendbuginfo","1");
}
else
{
appConst.setProperty("sendbuginfo","0");
}
appConst.setProperty("ut",""+ut);
//..Store the Properties into a file.
try
{
appConst.store(new FileOutputStream(TailMDI.APP_CONSTANTS_FILE),null);
}
catch(Exception ex)
{
//..Do Nothing
Trace.exception(ex);
}
}
else if(ae.getActionCommand() == "Ok")
{
//..Set the constant variables and file
TailInternalFrame.MAX_LINES_TO_DISPLAY = Integer.parseInt(maxLinesTextField.getText());
Tail.tailMDI.noOfProjects = Integer.parseInt(noOfProjToShowTextField.getText());
FileMenu.maxEntriesInRecentFilesMenu = Integer.parseInt(maxRecentFilesField.getText());
if(sendBugInfoCheckBox.isSelected())
{
Tail.tailMDI.sendBugInfo = 1;
}
else
{
Tail.tailMDI.sendBugInfo = 0;
}
//..Write to file
appConst.setProperty("maxlines",maxLinesTextField.getText());
appConst.setProperty("noofproj",noOfProjToShowTextField.getText());
appConst.setProperty("maxrecentfiles",maxRecentFilesField.getText());
if(sendBugInfoCheckBox.isSelected())
{
appConst.setProperty("sendbuginfo","1");
}
else
{
appConst.setProperty("sendbuginfo","0");
}
appConst.setProperty("ut",""+ut);
//..Store the Properties into a file.
try
{
appConst.store(new FileOutputStream(TailMDI.APP_CONSTANTS_FILE),null);
}
catch(Exception ex)
{
//..Do Nothing
Trace.exception(ex);
}
//..Close the dialog
settingsDialog.dispose();
}
else if(ae.getActionCommand() == "Cancel")
{
//..Close the dialog
settingsDialog.dispose();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Founder of MakeLogic - A Mobile Solutions and XML Web Services Company. B-Tech engineer from India's reputed IITs.
Designed and Authored products like MicroGraphs, MakeLogic VersionManager and MakeLogic Device Broker. Pls see http://www.makelogic.com
MakeLogic is a strategic business partner of Microsoft, Sun, IBM, HP and Citrix.
Contact : madanuuk@makelogic.com OR +91 - 40 - 55322433