[2185] | 1 | /*
|
---|
| 2 |
|
---|
| 3 | * PreferencesDialogt.java
|
---|
| 4 | * Copyright (C) 2001 New Zealand Digital Library Project
|
---|
| 5 |
|
---|
| 6 | *
|
---|
| 7 |
|
---|
| 8 | * This program is free software; you can redistribute it and/or modify
|
---|
| 9 |
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 |
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 |
|
---|
| 14 | * (at your option) any later version.
|
---|
| 15 |
|
---|
| 16 | *
|
---|
| 17 |
|
---|
| 18 | * This program is distributed in the hope that it will be useful,
|
---|
| 19 |
|
---|
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 |
|
---|
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 23 |
|
---|
| 24 | * GNU General Public License for more details.
|
---|
| 25 |
|
---|
| 26 | *
|
---|
| 27 |
|
---|
| 28 | * You should have received a copy of the GNU General Public License
|
---|
| 29 |
|
---|
| 30 | * along with this program; if not, write to the Free Software
|
---|
| 31 |
|
---|
| 32 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 33 |
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | package org.nzdl.gsdl.SimpleGraphicalClient;
|
---|
| 38 |
|
---|
[2270] | 39 | import org.nzdl.gsdl.util.NzdlConstants;
|
---|
[2188] | 40 | import org.nzdl.gsdl.util.NzdlPreferences;
|
---|
[2185] | 41 | import javax.swing.*;
|
---|
| 42 | import java.awt.*;
|
---|
| 43 | import java.awt.event.*;
|
---|
| 44 | import java.util.*;
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | public class PreferencesDialog extends JDialog implements ActionListener {
|
---|
| 49 |
|
---|
[2222] | 50 | private CSFrame parentFrame;
|
---|
[2185] | 51 | private JButton okButton, cancelButton;
|
---|
| 52 | private JPanel buttonPanel, holderPanel;
|
---|
| 53 | private Box contentBox;
|
---|
[2190] | 54 | private JCheckBox showFirstDocCheckBox, showAsTextCheckBox, connectToMultipleCheckBox, logNetworkLevelCheckBox, useCacheCheckBox, saveDocsCheckBox;
|
---|
| 55 |
|
---|
[2185] | 56 |
|
---|
| 57 |
|
---|
[2222] | 58 | PreferencesDialog(CSFrame f, String title, boolean modal) {
|
---|
[2185] | 59 | super(f, title, modal );
|
---|
[2222] | 60 | parentFrame = f;
|
---|
[2185] | 61 |
|
---|
| 62 | contentBox = Box.createVerticalBox();
|
---|
| 63 | // contentPanel = new JPanel();
|
---|
| 64 | // GridLayout grid = new GridLayout(0,2,5,5);
|
---|
| 65 |
|
---|
| 66 | buttonPanel = new JPanel();
|
---|
| 67 |
|
---|
| 68 | //editPanel.setLayout(new GridLayout(0,1,5,5));
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | JLabel prefTitle = new JLabel("Preferences", SwingConstants.CENTER);
|
---|
| 72 | prefTitle.setAlignmentX(JLabel.CENTER_ALIGNMENT);
|
---|
| 73 | JPanel prefTitlePanel = new JPanel();
|
---|
| 74 | prefTitlePanel.add(prefTitle);
|
---|
| 75 |
|
---|
| 76 | //contentBox.add();
|
---|
| 77 | // the preferences themselves ...
|
---|
[2188] | 78 |
|
---|
[2190] | 79 | showFirstDocCheckBox =
|
---|
[2270] | 80 | new JCheckBox( NzdlConstants.DISPLAY_FIRST_DOC, NzdlPreferences.getBoolean( NzdlConstants.DISPLAY_FIRST_DOC));
|
---|
[2188] | 81 | showFirstDocCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
| 82 |
|
---|
[2190] | 83 | showAsTextCheckBox =
|
---|
[2270] | 84 | new JCheckBox( NzdlConstants.RAW_TEXT, NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT));
|
---|
[2185] | 85 | showAsTextCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
[2188] | 86 |
|
---|
[2190] | 87 | connectToMultipleCheckBox =
|
---|
[2270] | 88 | new JCheckBox(NzdlConstants.MULTIPLE_SERVERS, NzdlPreferences.getBoolean(NzdlConstants.MULTIPLE_SERVERS));
|
---|
[2188] | 89 | connectToMultipleCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
| 90 |
|
---|
[2190] | 91 | logNetworkLevelCheckBox =
|
---|
[2270] | 92 | new JCheckBox(NzdlConstants.LOG_SERVICE, NzdlPreferences.getBoolean(NzdlConstants.LOG_SERVICE));
|
---|
[2188] | 93 | logNetworkLevelCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
| 94 |
|
---|
[2190] | 95 | useCacheCheckBox =
|
---|
[2270] | 96 | new JCheckBox(NzdlConstants.CACHE_CORBA, NzdlPreferences.getBoolean(NzdlConstants.CACHE_CORBA));
|
---|
[2188] | 97 | useCacheCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
| 98 |
|
---|
[2190] | 99 | saveDocsCheckBox =
|
---|
[2270] | 100 | new JCheckBox(NzdlConstants.SAVE_DOCS, NzdlPreferences.getBoolean(NzdlConstants.SAVE_DOCS));
|
---|
[2188] | 101 | saveDocsCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
| 102 |
|
---|
[2185] | 103 | // add the preferences ...
|
---|
| 104 |
|
---|
| 105 | contentBox.add(prefTitlePanel);
|
---|
| 106 | contentBox.add(showFirstDocCheckBox);
|
---|
| 107 | contentBox.add(showAsTextCheckBox);
|
---|
[2188] | 108 | contentBox.add(connectToMultipleCheckBox);
|
---|
| 109 | contentBox.add(logNetworkLevelCheckBox);
|
---|
| 110 | contentBox.add(useCacheCheckBox);
|
---|
| 111 | contentBox.add(saveDocsCheckBox);
|
---|
| 112 |
|
---|
[2185] | 113 | okButton = new JButton("Ok");
|
---|
| 114 | cancelButton = new JButton("Cancel");
|
---|
| 115 | okButton.setPreferredSize(new Dimension(80,20));
|
---|
| 116 | cancelButton.setPreferredSize(new Dimension(80,20));
|
---|
| 117 | okButton.addActionListener(this);
|
---|
| 118 | cancelButton.addActionListener(this);
|
---|
| 119 | buttonPanel.add( okButton );
|
---|
| 120 | buttonPanel.add( cancelButton );
|
---|
| 121 | getRootPane().setDefaultButton(okButton);
|
---|
| 122 |
|
---|
| 123 | holderPanel = new JPanel();
|
---|
| 124 | holderPanel.setBorder(BorderFactory.createEmptyBorder(10,10,2,10));
|
---|
| 125 | holderPanel.setLayout( new BorderLayout());
|
---|
| 126 | holderPanel.add( contentBox, BorderLayout.NORTH);
|
---|
| 127 | holderPanel.add( buttonPanel, BorderLayout.SOUTH);
|
---|
| 128 | getContentPane().add(holderPanel);
|
---|
| 129 | //setSize(new Dimension(300,300));
|
---|
| 130 |
|
---|
| 131 | pack();
|
---|
| 132 | setVisible(true);
|
---|
| 133 | } //end PreferencesDialog constructor
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | public void actionPerformed(ActionEvent e) {
|
---|
| 138 | Object source = e.getSource();
|
---|
| 139 | if (source == okButton)
|
---|
| 140 | {
|
---|
| 141 | //System.err.println("ok button pressed!");
|
---|
[2222] | 142 |
|
---|
[2270] | 143 | boolean oldRawText = NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT);
|
---|
[2222] | 144 |
|
---|
[2270] | 145 | NzdlPreferences.setBoolean(NzdlConstants.DISPLAY_FIRST_DOC,showFirstDocCheckBox.isSelected());
|
---|
| 146 | NzdlPreferences.setBoolean(NzdlConstants.RAW_TEXT, showAsTextCheckBox.isSelected());
|
---|
| 147 | NzdlPreferences.setBoolean(NzdlConstants.MULTIPLE_SERVERS, connectToMultipleCheckBox.isSelected());
|
---|
| 148 | NzdlPreferences.setBoolean(NzdlConstants.LOG_SERVICE,logNetworkLevelCheckBox.isSelected());
|
---|
| 149 | NzdlPreferences.setBoolean(NzdlConstants.CACHE_CORBA, useCacheCheckBox.isSelected());
|
---|
| 150 | NzdlPreferences.setBoolean(NzdlConstants.SAVE_DOCS, saveDocsCheckBox.isSelected());
|
---|
[2188] | 151 | NzdlPreferences.getInstance().save();
|
---|
[2195] | 152 |
|
---|
| 153 | // update the current display if raw text option has changed ?
|
---|
| 154 |
|
---|
[2270] | 155 | boolean newRawText = NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT);
|
---|
[2222] | 156 |
|
---|
| 157 | if (oldRawText != newRawText) {
|
---|
| 158 | //System.err.println("raw text option changed");
|
---|
| 159 | if (newRawText) {
|
---|
| 160 | // kludgy direct access to instance and method
|
---|
| 161 | parentFrame.searchPanel.switchToRawText();
|
---|
| 162 | }
|
---|
| 163 | else
|
---|
| 164 | // kludgy direct access to instance and method
|
---|
| 165 | parentFrame.searchPanel.switchToHTML();
|
---|
| 166 | } // end if oldRawText != newRawTex
|
---|
| 167 |
|
---|
[2188] | 168 | dispose(); //close window
|
---|
[2222] | 169 | } // end if source == okButton
|
---|
[2185] | 170 | else
|
---|
| 171 | {
|
---|
| 172 | if (source == cancelButton)
|
---|
| 173 | {
|
---|
| 174 | dispose();
|
---|
| 175 | }
|
---|
| 176 | else
|
---|
| 177 | System.err.println("event not processed in PreferencesDialog");
|
---|
| 178 | }
|
---|
| 179 | } //end actionPerformed
|
---|
| 180 |
|
---|
| 181 | } // end PreferencesDialog class
|
---|