source: trunk/gli/src/org/greenstone/gatherer/cdm/MacrosManager.java@ 12123

Last change on this file since 12123 was 12123, checked in by kjdon, 18 years ago

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: Katherine Don, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 2006 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.util.*;
32import javax.swing.*;
33import javax.swing.event.*;
34import java.io.File;
35import java.io.FileInputStream;
36import java.io.FileOutputStream;
37import java.io.BufferedReader;
38import java.io.BufferedWriter;
39import java.io.InputStreamReader;
40import java.io.OutputStreamWriter;
41
42import org.greenstone.gatherer.collection.CollectionManager;
43import org.greenstone.gatherer.Configuration;
44import org.greenstone.gatherer.Dictionary;
45import org.greenstone.gatherer.gui.DesignPaneHeader;
46import org.greenstone.gatherer.gui.GLIButton;
47
48public class MacrosManager
49 extends JPanel {
50
51 /** The controls used to modify the general options. */
52 private Control controls;
53 /** Constructor. */
54 public MacrosManager() {
55 }
56
57
58 /** Destructor. */
59 public void destroy() {
60 if (controls != null) {
61 controls.destroy();
62 controls = null;
63 }
64 }
65
66 public void loseFocus() {
67 }
68
69 public void gainFocus() {
70
71 }
72 /** This class is resposible for generating the controls for the editing of general options.
73 * @return the Control for editing the general options
74 */
75 public Control getControls() {
76 if (controls == null) {
77 controls = new MacrosControl();
78 }
79 return controls;
80 }
81
82
83 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
84 * @param mode the new mode as an int
85 */
86 public void modeChanged(int mode) {
87
88 }
89
90
91 private class MacrosControl
92 extends JPanel
93 implements Control {
94
95 JTextArea macros_textarea = null;
96 JButton save_button = null;
97 JButton revert_button = null;
98
99 public MacrosControl() {
100 super();
101
102 JPanel header_pane = new DesignPaneHeader("CDM.GUI.Macros", "collectionspecificmacros");
103
104 JPanel main_pane = new JPanel();
105 main_pane.setLayout(new BorderLayout());
106 macros_textarea = new JTextArea();
107 macros_textarea.setBackground(Configuration.getColor("coloring.editable_background", false));
108 macros_textarea.setCaretPosition(0);
109 macros_textarea.setLineWrap(false);
110 macros_textarea.setWrapStyleWord(false);
111 macros_textarea.setToolTipText(Dictionary.get("CDM.MacrosManager.Editor_Tooltip"));
112
113 JPanel macros_pane = new JPanel();
114 macros_pane.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
115 macros_pane.setLayout(new BorderLayout());
116 macros_pane.add(new JScrollPane(macros_textarea), BorderLayout.CENTER);
117
118 save_button = new GLIButton(Dictionary.get("CDM.MacrosManager.Save"), Dictionary.get("CDM.MacrosManager.Save_Tooltip"));
119 revert_button = new GLIButton(Dictionary.get("CDM.MacrosManager.Revert"), Dictionary.get("CDM.MacrosManager.Revert_Tooltip"));
120
121 save_button.addActionListener(new SaveListener());
122 revert_button.addActionListener(new RevertListener());
123 JPanel button_pane = new JPanel();
124 button_pane.setLayout(new GridLayout(1,2));
125 button_pane.add(save_button);
126 button_pane.add(revert_button);
127
128 main_pane.add(macros_pane, BorderLayout.CENTER);
129 main_pane.add(button_pane, BorderLayout.SOUTH);
130
131 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
132 setLayout(new BorderLayout());
133 add(header_pane, BorderLayout.NORTH);
134 add(main_pane, BorderLayout.CENTER);
135 }
136
137 public void destroy() {
138 }
139
140 public void loseFocus() {
141 }
142
143 public void gainFocus() {
144 readMacroFile();
145 }
146
147 private void readMacroFile() {
148 macros_textarea.setText("");
149 File extra_dm = new File(CollectionManager.getCollectionDirectoryPath()+"macros"+File.separator+"extra.dm");
150
151 if (extra_dm.exists()) {
152 try {
153 BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(extra_dm), "UTF-8"));
154
155 String line;
156 while ((line = br.readLine()) != null) {
157 macros_textarea.append(line+"\n");
158 }
159 } catch (Exception e) {
160 System.err.println("Exception happened, "+e.getMessage());
161 }
162 }
163 }
164
165 private void writeMacroFile() {
166 File extra_dm = new File(CollectionManager.getCollectionDirectoryPath()+"macros"+File.separator+"extra.dm");
167 try {
168 if (!extra_dm.exists()) {
169 File parent_dir = extra_dm.getParentFile();
170 parent_dir.mkdirs();
171 extra_dm.createNewFile();
172 }
173
174 BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(extra_dm), "UTF-8"));
175 String text = macros_textarea.getText();
176 out.write(text, 0, text.length());
177 out.newLine();
178 out.flush();
179 out.close();
180 } catch (Exception e) {
181
182 }
183 }
184 private class SaveListener
185 implements ActionListener {
186
187 public void actionPerformed(ActionEvent event) {
188 writeMacroFile();
189 }
190 }
191
192 private class RevertListener
193 implements ActionListener {
194
195 public void actionPerformed(ActionEvent event) {
196 readMacroFile();
197 }
198 }
199 }
200
201}
Note: See TracBrowser for help on using the repository browser.