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 |
|
---|
39 | import org.nzdl.gsdl.util.NzdlConstants;
|
---|
40 | import org.nzdl.gsdl.util.NzdlPreferences;
|
---|
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 |
|
---|
50 | private CSFrame parentFrame;
|
---|
51 | private JButton okButton, cancelButton;
|
---|
52 | private JPanel buttonPanel, holderPanel;
|
---|
53 | private Box contentBox;
|
---|
54 | private JCheckBox showFirstDocCheckBox, showAsTextCheckBox, connectToMultipleCheckBox, logNetworkLevelCheckBox, useCacheCheckBox, saveDocsCheckBox;
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 | PreferencesDialog(CSFrame f, String title, boolean modal) {
|
---|
59 | super(f, title, modal );
|
---|
60 | parentFrame = f;
|
---|
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 ...
|
---|
78 |
|
---|
79 | showFirstDocCheckBox =
|
---|
80 | new JCheckBox( NzdlConstants.DISPLAY_FIRST_DOC, NzdlPreferences.getBoolean( NzdlConstants.DISPLAY_FIRST_DOC));
|
---|
81 | showFirstDocCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
82 |
|
---|
83 | showAsTextCheckBox =
|
---|
84 | new JCheckBox( NzdlConstants.RAW_TEXT, NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT));
|
---|
85 | showAsTextCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
86 |
|
---|
87 | connectToMultipleCheckBox =
|
---|
88 | new JCheckBox(NzdlConstants.MULTIPLE_SERVERS, NzdlPreferences.getBoolean(NzdlConstants.MULTIPLE_SERVERS));
|
---|
89 | connectToMultipleCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
90 |
|
---|
91 | logNetworkLevelCheckBox =
|
---|
92 | new JCheckBox(NzdlConstants.LOG_SERVICE, NzdlPreferences.getBoolean(NzdlConstants.LOG_SERVICE));
|
---|
93 | logNetworkLevelCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
94 |
|
---|
95 | useCacheCheckBox =
|
---|
96 | new JCheckBox(NzdlConstants.CACHE_CORBA, NzdlPreferences.getBoolean(NzdlConstants.CACHE_CORBA));
|
---|
97 | useCacheCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
98 |
|
---|
99 | saveDocsCheckBox =
|
---|
100 | new JCheckBox(NzdlConstants.SAVE_DOCS, NzdlPreferences.getBoolean(NzdlConstants.SAVE_DOCS));
|
---|
101 | saveDocsCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
|
---|
102 |
|
---|
103 | // add the preferences ...
|
---|
104 |
|
---|
105 | contentBox.add(prefTitlePanel);
|
---|
106 | contentBox.add(showFirstDocCheckBox);
|
---|
107 | contentBox.add(showAsTextCheckBox);
|
---|
108 | contentBox.add(connectToMultipleCheckBox);
|
---|
109 | contentBox.add(logNetworkLevelCheckBox);
|
---|
110 | contentBox.add(useCacheCheckBox);
|
---|
111 | contentBox.add(saveDocsCheckBox);
|
---|
112 |
|
---|
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!");
|
---|
142 |
|
---|
143 | boolean oldRawText = NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT);
|
---|
144 |
|
---|
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());
|
---|
151 | NzdlPreferences.getInstance().save();
|
---|
152 |
|
---|
153 | // update the current display if raw text option has changed ?
|
---|
154 |
|
---|
155 | boolean newRawText = NzdlPreferences.getBoolean(NzdlConstants.RAW_TEXT);
|
---|
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 |
|
---|
168 | dispose(); //close window
|
---|
169 | } // end if source == okButton
|
---|
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
|
---|