/* * PreferencesDialogt.java * Copyright (C) 2001 New Zealand Digital Library Project * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.nzdl.gsdl.SimpleGraphicalClient; import org.nzdl.gsdl.util.NzdlConstants; import org.nzdl.gsdl.util.NzdlPreferences; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class PreferencesDialog extends JDialog implements ActionListener { private CSFrame parentFrame; private JButton okButton, cancelButton; private JPanel buttonPanel, holderPanel; private Box contentBox; private JCheckBox showFirstDocCheckBox, showAsTextCheckBox, connectToMultipleCheckBox, logNetworkLevelCheckBox, useCacheCheckBox, saveDocsCheckBox; PreferencesDialog(CSFrame f, String title, boolean modal) { super(f, title, modal ); parentFrame = f; contentBox = Box.createVerticalBox(); // contentPanel = new JPanel(); // GridLayout grid = new GridLayout(0,2,5,5); buttonPanel = new JPanel(); //editPanel.setLayout(new GridLayout(0,1,5,5)); JLabel prefTitle = new JLabel("Preferences", SwingConstants.CENTER); prefTitle.setAlignmentX(JLabel.CENTER_ALIGNMENT); JPanel prefTitlePanel = new JPanel(); prefTitlePanel.add(prefTitle); //contentBox.add(); // the preferences themselves ... showFirstDocCheckBox = new JCheckBox( NzdlConstants.DISPLAY_FIRST_DOC, NzdlPreferences.getBoolean( NzdlConstants.DISPLAY_FIRST_DOC)); showFirstDocCheckBox.setHorizontalAlignment(SwingConstants.LEFT); showAsTextCheckBox = new JCheckBox( NzdlConstants.RAW_TEXT, NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT)); showAsTextCheckBox.setHorizontalAlignment(SwingConstants.LEFT); connectToMultipleCheckBox = new JCheckBox(NzdlConstants.MULTIPLE_SERVERS, NzdlPreferences.getBoolean(NzdlConstants.MULTIPLE_SERVERS)); connectToMultipleCheckBox.setHorizontalAlignment(SwingConstants.LEFT); logNetworkLevelCheckBox = new JCheckBox(NzdlConstants.LOG_SERVICE, NzdlPreferences.getBoolean(NzdlConstants.LOG_SERVICE)); logNetworkLevelCheckBox.setHorizontalAlignment(SwingConstants.LEFT); useCacheCheckBox = new JCheckBox(NzdlConstants.CACHE_CORBA, NzdlPreferences.getBoolean(NzdlConstants.CACHE_CORBA)); useCacheCheckBox.setHorizontalAlignment(SwingConstants.LEFT); saveDocsCheckBox = new JCheckBox(NzdlConstants.SAVE_DOCS, NzdlPreferences.getBoolean(NzdlConstants.SAVE_DOCS)); saveDocsCheckBox.setHorizontalAlignment(SwingConstants.LEFT); // add the preferences ... contentBox.add(prefTitlePanel); contentBox.add(showFirstDocCheckBox); contentBox.add(showAsTextCheckBox); contentBox.add(connectToMultipleCheckBox); contentBox.add(logNetworkLevelCheckBox); contentBox.add(useCacheCheckBox); contentBox.add(saveDocsCheckBox); okButton = new JButton("Ok"); cancelButton = new JButton("Cancel"); okButton.setPreferredSize(new Dimension(80,20)); cancelButton.setPreferredSize(new Dimension(80,20)); okButton.addActionListener(this); cancelButton.addActionListener(this); buttonPanel.add( okButton ); buttonPanel.add( cancelButton ); getRootPane().setDefaultButton(okButton); holderPanel = new JPanel(); holderPanel.setBorder(BorderFactory.createEmptyBorder(10,10,2,10)); holderPanel.setLayout( new BorderLayout()); holderPanel.add( contentBox, BorderLayout.NORTH); holderPanel.add( buttonPanel, BorderLayout.SOUTH); getContentPane().add(holderPanel); //setSize(new Dimension(300,300)); pack(); setVisible(true); } //end PreferencesDialog constructor public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == okButton) { //System.err.println("ok button pressed!"); boolean oldRawText = NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT); NzdlPreferences.setBoolean(NzdlConstants.DISPLAY_FIRST_DOC,showFirstDocCheckBox.isSelected()); NzdlPreferences.setBoolean(NzdlConstants.RAW_TEXT, showAsTextCheckBox.isSelected()); NzdlPreferences.setBoolean(NzdlConstants.MULTIPLE_SERVERS, connectToMultipleCheckBox.isSelected()); NzdlPreferences.setBoolean(NzdlConstants.LOG_SERVICE,logNetworkLevelCheckBox.isSelected()); NzdlPreferences.setBoolean(NzdlConstants.CACHE_CORBA, useCacheCheckBox.isSelected()); NzdlPreferences.setBoolean(NzdlConstants.SAVE_DOCS, saveDocsCheckBox.isSelected()); NzdlPreferences.getInstance().save(); // update the current display if raw text option has changed ? boolean newRawText = NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT); if (oldRawText != newRawText) { //System.err.println("raw text option changed"); if (newRawText) { // kludgy direct access to instance and method parentFrame.searchPanel.switchToRawText(); } else // kludgy direct access to instance and method parentFrame.searchPanel.switchToHTML(); } // end if oldRawText != newRawTex dispose(); //close window } // end if source == okButton else { if (source == cancelButton) { dispose(); } else System.err.println("event not processed in PreferencesDialog"); } } //end actionPerformed } // end PreferencesDialog class