Changeset 29031
- Timestamp:
- 2014-05-02T20:11:21+12:00 (10 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/gui/FormatConversionDialog.java
r29030 r29031 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 * Copyright (C) 1999 New Zealand Digital Library Project 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 *######################################################################## 24 */ 25 1 26 package org.greenstone.gatherer.gui; 2 27 … … 4 29 import org.greenstone.gatherer.Dictionary; 5 30 import org.greenstone.gatherer.Gatherer; 6 //import static org.greenstone.gatherer.cdm.Format4gs3Manager.NumberedJTextArea;7 31 import org.greenstone.gatherer.cdm.CollectionConfigXMLReadWrite; 8 32 import org.greenstone.gatherer.util.Codec; … … 10 34 import org.greenstone.gatherer.util.OutputStreamGobbler; 11 35 import org.greenstone.gatherer.util.StaticStrings; 12 import org.greenstone.gatherer.util.Utility;13 36 import org.greenstone.gatherer.util.XMLTools; 14 37 15 import org.fife.ui.rsyntaxtextarea.*;16 38 import org.w3c.dom.*; 17 39 18 import java.io.BufferedReader;19 import java.io.BufferedWriter;20 import java.io.Closeable;21 40 import java.io.File; 22 import java.io.InputStream;23 import java.io.InputStreamReader;24 41 import java.io.IOException; 25 import java.io.OutputStream; 26 import java.io.OutputStreamWriter; 27 28 //import java.awt.Dimension; 42 29 43 import java.awt.*; 30 44 import java.awt.event.*; … … 33 47 import javax.swing.border.*; 34 48 import javax.swing.event.*; 35 import javax.swing.undo.*;36 49 37 50 … … 39 52 // + StreamGobblers: http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html 40 53 // Need to test on Windows: the Ctrl-D/Ctrl-Z sent to formatconverter.exe. May not need to do anything special for Windows now that this code is using StreamGobblers to process the in/out streams of the process 41 // Need to use dictionary for labels42 // convertFormat() for remote GS54 // + Need to use dictionary for labels 55 // X convertFormat() for remote GS. Remote does not display Format Conversion wizard 43 56 // + HTML tidy (put all "<br/>" back to "<br>" in luce/etc/collectionConfig.xml and run again) 44 // Help tooltips on buttons57 // + Help tooltips on buttons 45 58 // + Undo, Redo buttons 46 59 // X Split class into dialog/widgets and data processing? … … 80 93 private GLIButton next_button = null; 81 94 private GLIButton accept_all_button = null; 82 private GLIButton gs2_undo_button = null;83 private GLIButton gs2_redo_button = null;84 private GLIButton gs3_undo_button = null;85 private GLIButton gs3_redo_button = null;86 95 private GLIButton htmltidy_button = null; 87 96 private GLIButton xmltidy_button = null; 97 // the 2 NumberedJTextAreas. Each provide their own undo and redo buttons already hooked up to listeners 88 98 private NumberedJTextArea gs2_textarea = null; 89 99 private NumberedJTextArea gs3_textarea = null; … … 104 114 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 105 115 106 107 gs2_textarea = new NumberedJTextArea(); 108 gs3_textarea = new NumberedJTextArea(); 116 // The NumberedJTextArea provides its own undo and redo buttons, already hooked up to listeners 117 // Just need to place these buttons in the dialog 118 gs2_textarea = new NumberedJTextArea("gs2", Dictionary.get("FormatConversionDialog.GS2_Text_Tooltip")); 119 gs3_textarea = new NumberedJTextArea("gs3", Dictionary.get("FormatConversionDialog.GS3_Text_Tooltip")); 109 120 110 121 … … 112 123 midbutton_panel.setComponentOrientation(Dictionary.getOrientation()); 113 124 114 gs2_undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip"));115 gs2_undo_button.setEnabled(false);116 117 gs2_redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip"));118 gs2_redo_button.setEnabled(false);119 120 gs2_undo_button.addActionListener(new UndoListener(gs2_textarea, gs2_undo_button, gs2_redo_button));121 gs2_redo_button.addActionListener(new RedoListener(gs2_textarea, gs2_undo_button, gs2_redo_button));122 123 125 JButton reconvert_button = new GLIButton(Dictionary.get("FormatConversionDialog.Reconvert"), Dictionary.get("FormatConversionDialog.Reconvert_Tooltip")); 124 126 125 midbutton_panel.add(gs2_ undo_button);126 midbutton_panel.add(gs2_ redo_button);127 midbutton_panel.add(gs2_textarea.undoButton); 128 midbutton_panel.add(gs2_textarea.redoButton); 127 129 midbutton_panel.add(reconvert_button); 128 130 reconvert_button.addActionListener(new ReconvertListener()); … … 135 137 JPanel button1_panel = new JPanel(); 136 138 button1_panel.setComponentOrientation(Dictionary.getOrientation()); 137 gs3_undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip"));138 gs3_undo_button.setEnabled(false);139 140 gs3_redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip"));141 gs3_redo_button.setEnabled(false);142 143 gs3_undo_button.addActionListener(new UndoListener(gs3_textarea, gs3_undo_button, gs3_redo_button));144 gs3_redo_button.addActionListener(new RedoListener(gs3_textarea, gs3_undo_button, gs3_redo_button));145 146 139 147 140 xmltidy_button = new GLIButton(Dictionary.get("FormatConversionDialog.XHTML_Tidy"), Dictionary.get("FormatConversionDialog.XHTML_Tidy_Tooltip")); 148 141 xmltidy_button.addActionListener(new XMLTidyButtonListener()); 149 142 150 button1_panel.add(gs3_ undo_button);151 button1_panel.add(gs3_ redo_button);143 button1_panel.add(gs3_textarea.undoButton); 144 button1_panel.add(gs3_textarea.redoButton); 152 145 button1_panel.add(xmltidy_button); 153 146 … … 167 160 168 161 169 // The undoable text areas. Adding the UndoableEditListener has to come after instantiation170 // of the undo and redo buttons, since the listener expects these buttons to already exist171 172 gs2_textarea.getDocument().addUndoableEditListener(new CustomUndoableEditListener(gs2_undo_button, gs2_redo_button));173 gs3_textarea.getDocument().addUndoableEditListener(new CustomUndoableEditListener(gs3_undo_button, gs3_redo_button));174 175 initTextArea(gs2_textarea);176 initTextArea(gs3_textarea);177 gs2_textarea.setToolTipText(Dictionary.get("FormatConversionDialog.GS2_Text_Tooltip"));178 gs3_textarea.setToolTipText(Dictionary.get("FormatConversionDialog.GS3_Text_Tooltip"));179 180 181 162 JPanel centre_panel = new JPanel(); 182 163 centre_panel.setLayout(new BoxLayout(centre_panel, BoxLayout.Y_AXIS)); … … 221 202 } 222 203 223 224 public static void initTextArea(NumberedJTextArea editor_textarea) {225 /* Fields specific to RSyntaxQuery inherited class */226 editor_textarea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);227 editor_textarea.setBracketMatchingEnabled(true);228 editor_textarea.setAnimateBracketMatching(true);229 editor_textarea.setAntiAliasingEnabled(true);230 editor_textarea.setAutoIndentEnabled(true);231 editor_textarea.setPaintMarkOccurrencesBorder(false);232 233 /* Standard fields to JTextArea */234 editor_textarea.setOpaque(false);235 editor_textarea.setBackground(Configuration.getColor("coloring.editable_background", false));236 editor_textarea.setCaretPosition(0);237 editor_textarea.setLineWrap(true);238 editor_textarea.setRows(11);239 editor_textarea.setWrapStyleWord(false);240 }241 204 242 205 public int getDialogResult() { … … 654 617 655 618 // as we're on a new screen of dialog, need to clear all undo/redo history 656 gs2_undo_button.setEnabled(false); 657 gs2_redo_button.setEnabled(false); 658 gs3_undo_button.setEnabled(false); 659 gs3_redo_button.setEnabled(false); 660 gs2_textarea.discardAllEdits(); 619 gs2_textarea.discardAllEdits(); // will disable redo/undo buttons 661 620 gs3_textarea.discardAllEdits(); 662 621 … … 750 709 751 710 //******************INNER CLASSES including LISTENERS and STREAMGOBBLERS****************// 752 753 /**754 * A textarea with the line number next to each line of the text755 */756 public class NumberedJTextArea extends RSyntaxTextArea /* JTextArea */757 {758 public void paintComponent(Graphics g)759 {760 Insets insets = getInsets();761 Rectangle rectangle = g.getClipBounds();762 g.setColor(Color.white);763 g.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);764 765 super.paintComponent(g);766 767 if (rectangle.x < insets.left)768 {769 FontMetrics font_metrics = g.getFontMetrics();770 int font_height = font_metrics.getHeight();771 int y = font_metrics.getAscent() + insets.top;772 int line_number_start_point = ((rectangle.y + insets.top) / font_height) + 1;773 if (y < rectangle.y)774 {775 y = line_number_start_point * font_height - (font_height - font_metrics.getAscent());776 }777 int y_axis_end_point = y + rectangle.height + font_height;778 int x_axis_start_point = insets.left;779 x_axis_start_point -= getFontMetrics(getFont()).stringWidth(Math.max(getRows(), getLineCount() + 1) + " ");780 if (!this.getText().trim().equals(""))781 {782 g.setColor(Color.DARK_GRAY);783 }784 else785 {786 g.setColor(Color.white);787 }788 int length = ("" + Math.max(getRows(), getLineCount() + 1)).length();789 while (y < y_axis_end_point)790 {791 g.drawString(line_number_start_point + " ", x_axis_start_point, y);792 y += font_height;793 line_number_start_point++;794 }795 }796 }797 798 799 public Insets getInsets()800 {801 Insets insets = super.getInsets(new Insets(0, 0, 0, 0));802 insets.left += getFontMetrics(getFont()).stringWidth(Math.max(getRows(), getLineCount() + 1) + " ");803 return insets;804 }805 }806 711 807 712 // windowClosing() is called when the user presses the top-right close button the dialog … … 951 856 } 952 857 953 private class UndoListener implements ActionListener954 {955 NumberedJTextArea textarea = null;956 GLIButton undobutton, redobutton;957 958 public UndoListener(NumberedJTextArea textarea, GLIButton undobutton, GLIButton redobutton) {959 960 this.textarea = textarea;961 this.undobutton = undobutton;962 this.redobutton = redobutton;963 964 }965 966 public void actionPerformed(ActionEvent event)967 {968 try {969 if (textarea.canUndo()) {970 redobutton.setEnabled(true);971 textarea.undoLastAction();972 }973 974 if (!textarea.canUndo()) {975 undobutton.setEnabled(false);976 } else {977 undobutton.setEnabled(true);978 }979 980 } catch (Exception e) {981 System.err.println("Exception trying to undo: " + e.getMessage());982 e.printStackTrace();983 }984 }985 }986 987 private class RedoListener implements ActionListener988 {989 NumberedJTextArea textarea = null;990 GLIButton undobutton, redobutton;991 992 public RedoListener(NumberedJTextArea textarea, GLIButton undobutton, GLIButton redobutton) {993 994 this.textarea = textarea;995 this.undobutton = undobutton;996 this.redobutton = redobutton;997 }998 999 public void actionPerformed(ActionEvent evt)1000 {1001 try {1002 if (textarea.canRedo()) {1003 undobutton.setEnabled(true); // the difference with Format4gs3Manager, and no DocumentListener1004 textarea.redoLastAction();1005 }1006 1007 if (!textarea.canRedo()) {1008 redobutton.setEnabled(false);1009 } else {1010 redobutton.setEnabled(true);1011 }1012 1013 } catch (Exception e) {1014 System.err.println("Exception trying to redo: " + e.getMessage());1015 e.printStackTrace();1016 }1017 }1018 }1019 1020 private class CustomUndoableEditListener implements UndoableEditListener {1021 GLIButton undobutton = null;1022 GLIButton redobutton = null;1023 1024 public CustomUndoableEditListener(GLIButton undo_button, GLIButton redo_button) {1025 undobutton = undo_button;1026 redobutton = redo_button;1027 }1028 1029 public void undoableEditHappened(UndoableEditEvent evt)1030 {1031 undobutton.setEnabled(true);1032 redobutton.setEnabled(false);1033 }1034 }1035 858 } -
main/trunk/gli/src/org/greenstone/gatherer/util/InputStreamGobbler.java
r29017 r29031 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 * Copyright (C) 1999 New Zealand Digital Library Project 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 *######################################################################## 24 */ 25 1 26 package org.greenstone.gatherer.util; 2 27 … … 11 36 12 37 // http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html?page=2 13 // This class is used in FormatConversionDialog to properly read from the output and error streams of a Process 38 // This class is used in FormatConversionDialog to properly read from the stdout and stderr 39 // streams of a Process, Process.getInputStream() and Process.getErrorSream() 14 40 public class InputStreamGobbler extends Thread 15 41 { -
main/trunk/gli/src/org/greenstone/gatherer/util/OutputStreamGobbler.java
r29017 r29031 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 * Copyright (C) 1999 New Zealand Digital Library Project 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 *######################################################################## 24 */ 25 1 26 package org.greenstone.gatherer.util; 2 27 … … 12 37 // http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html?page=2 13 38 // This class is used in FormatConversionDialog to properly write to the inputstream of a Process 39 // Process.getOutputStream() 14 40 public class OutputStreamGobbler extends Thread 15 41 {
Note:
See TracChangeset
for help on using the changeset viewer.