TiblEdit's diacritics panel now works -- dia.dat has been added to the

repository and to TiblEdit's jar.
This commit is contained in:
dchandler 2004-04-14 05:12:00 +00:00
parent f09a03c9c7
commit 244a9d1370
5 changed files with 318 additions and 198 deletions

View file

@ -1109,6 +1109,11 @@ Contributor(s): ______________________________________.
<include name="org/thdl/tib/**/*.ini"/> <include name="org/thdl/tib/**/*.ini"/>
</fileset> </fileset>
</copy> </copy>
<copy todir="${mybin}">
<fileset dir="${source}">
<include name="org/thdl/tib/bibl/dia.dat"/>
</fileset>
</copy>
<copy todir="${mybin}"> <copy todir="${mybin}">
<fileset dir="${source}"> <fileset dir="${source}">
<include name="keyboards.ini"/> <include name="keyboards.ini"/>

View file

@ -29,7 +29,9 @@ import java.awt.event.MouseEvent;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -42,222 +44,232 @@ import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import javax.swing.text.*; import javax.swing.text.*;
/** /**
*<p> * <p>This class creates a panel that displays all the relevant
* This class creates a panel that displays all the relevant diacritic characters used in Asian Studies. * diacritic characters used in Asian Studies. In the context of
* In the context of TibEdit, it's constructor takes a TibFrame which is its parent. When the mouse is clicked * TiblEdit, its constructor takes a TibFrame which is its
* on any diacritic character displayed in DiacriticPanel, it inserts that character at the cursor of the * parent. When the mouse is clicked on any diacritic character
* TibFrame's {@link TextPane}. All characters are, of course, in Unicode. The file that is the list of diacrtics * displayed in DiacriticPanel, it inserts that character at the
* is dia.dat in the /bin/ directory. It is a flat file list of the hexadecimal codes for the Unicode diacritics. * cursor of the TibFrame's {@link TextPane}. All characters are,
* These are read and converted into characters by DiacriticPanel and they are displayed in the order they are read. * of course, in Unicode. The file that is the list of diacritics
* Thus, to reorder, modify, or add diacritics, one needs only to make the appropriate changes to the dia.dat file. * is dia.dat in the same directory as this class's class file. It
* </p> * is a flat file list of the hexadecimal codes for the Unicode
* * diacritics. These are read and converted into characters by
* @author Than Garson, Tibetan and Himalayan Digital Library * DiacriticPanel and they are displayed in the order they are
*/ * read. Thus, to reorder, modify, or add diacritics, one needs
* only to make the appropriate changes to the dia.dat file.</p>
*
* @author Than Garson, Tibetan and Himalayan Digital Library */
public class DiacriticPanel extends JPanel implements TibConstants public class DiacriticPanel extends JPanel implements TibConstants
{ {
// Attributes // Attributes
protected TibFrame frame; protected TibFrame frame;
protected JTextComponent jtc; protected JTextComponent jtc;
private TiblEdit controller; private TiblEdit controller;
//private StringTokenizer dataSplitter; //private StringTokenizer dataSplitter;
private char chosenChar; private char chosenChar;
private boolean hasPicked; private boolean hasPicked; // DLC FIXME: unused
private boolean isGeneral; private boolean isGeneral;
/** /**
* Sets the panel's layout, size, and background, and reads in the diacritic data. * Sets the panel's layout, size, and background, and reads in the diacritic data.
*/ */
private void init() private void init()
{ {
// Creating content panel to use for frame's content & initialize // Creating content panel to use for frame's content & initialize
//JPanel charPanel = new JPanel(new BorderLayout()); //JPanel charPanel = new JPanel(new BorderLayout());
setLayout(new GridLayout(0,3)); setLayout(new GridLayout(0,3));
setSize(new Dimension(100,450)); setSize(new Dimension(100,450));
setBackground(Color.white); setBackground(Color.white);
// Split the data, create individual line labels // Split the data, create individual line labels
try { try {
BufferedReader br = new BufferedReader(new FileReader(new File(DEFAULT_DIRECTORY + DIA_DATA))); URL url = DiacriticPanel.class.getResource(DIA_DATA);
String line = br.readLine(); if (url == null) {
while(line != null) { System.err.println("Cannot find " + DIA_DATA + "; aborting.");
char diaChar = (char)Long.parseLong(line.trim(),16); System.exit(1);
String diaStr = Character.toString(diaChar); }
JLabel diaLab = getDiaLabel(diaStr); InputStreamReader isr = new InputStreamReader(url.openStream());
this.add(diaLab); BufferedReader br = new BufferedReader(isr);
line = br.readLine(); String line = br.readLine();
} while(line != null) {
br.close(); char diaChar = (char)Long.parseLong(line.trim(),16);
} catch (IOException ioe) { String diaStr = Character.toString(diaChar);
System.out.println("An IOE caught: " + ioe.getMessage()); JLabel diaLab = getDiaLabel(diaStr);
ioe.printStackTrace(); this.add(diaLab);
} line = br.readLine();
} }
br.close();
} catch (IOException ioe) {
System.out.println("An IOE caught: " + ioe.getMessage());
ioe.printStackTrace();
org.thdl.util.ThdlDebug.noteIffyCode();
}
}
// Accessors // Accessors
/** /**
* This method takes a character, which is actually a String variable and creates a label * This method takes a character, which is actually a String variable and creates a label
* with a border and a margin with the supplied character string as the * with a border and a margin with the supplied character string as the
* centered text. Adds a MouseListener that is a {@link DiacriticPanel.TiblEditMouseAdapter}. It is called by the {@link #init} method. * centered text. Adds a MouseListener that is a {@link DiacriticPanel.TiblEditMouseAdapter}. It is called by the {@link #init} method.
* *
* @param ch - A string variable that is the character associated with this label/button. * @param ch - A string variable that is the character associated with this label/button.
* *
* @return JLabel - the label created. * @return JLabel - the label created.
*/ */
public JLabel getDiaLabel(String ch) public JLabel getDiaLabel(String ch)
{ {
JLabel lab = new JLabel(ch); JLabel lab = new JLabel(ch);
lab.setFont(DEFAULT_FONT); lab.setFont(DEFAULT_FONT);
lab.setHorizontalAlignment(SwingConstants.CENTER); lab.setHorizontalAlignment(SwingConstants.CENTER);
lab.setBorder(new CompoundBorder(new LineBorder(Color.black),BorderFactory.createEmptyBorder(2,2,2,2))); lab.setBorder(new CompoundBorder(new LineBorder(Color.black),BorderFactory.createEmptyBorder(2,2,2,2)));
if(isGeneral) { if(isGeneral) {
lab.addMouseListener(new GenMouseAdapter()); lab.addMouseListener(new GenMouseAdapter());
} else { } else {
lab.addMouseListener(new TiblEditMouseAdapter()); lab.addMouseListener(new TiblEditMouseAdapter());
} }
return lab; return lab;
} }
public void setChosenChar(char aChar) public void setChosenChar(char aChar)
{ {
chosenChar = aChar; chosenChar = aChar;
hasPicked = true; hasPicked = true;
} }
public char getChosenChar() public char getChosenChar()
{ {
char rValue = chosenChar; char rValue = chosenChar;
chosenChar = ' '; chosenChar = ' ';
hasPicked = false; hasPicked = false;
return rValue; return rValue;
} }
public void setController(TiblEdit te) public void setController(TiblEdit te)
{ {
controller = te; controller = te;
} }
public TiblEdit getController() public TiblEdit getController()
{ {
return controller; return controller;
} }
public void setFrame(TibFrame tf) public void setFrame(TibFrame tf)
{ {
frame = tf; frame = tf;
} }
public JFrame getFrame() public JFrame getFrame()
{ {
return frame; return frame;
} }
public void setJTC(JTextComponent jtextc) public void setJTC(JTextComponent jtextc)
{ {
jtc = jtextc; jtc = jtextc;
} }
public JTextComponent getJTC() public JTextComponent getJTC()
{ {
return jtc; return jtc;
} }
// Constructors // Constructors
public DiacriticPanel(boolean isGen, Container cont) public DiacriticPanel(boolean isGen, Container cont)
{ {
super(); super();
isGeneral = isGen; isGeneral = isGen;
if(cont instanceof TibFrame) { if(cont instanceof TibFrame) {
setFrame((TibFrame)cont); setFrame((TibFrame)cont);
} else if(cont instanceof JTextComponent) { } else if(cont instanceof JTextComponent) {
setJTC((JTextComponent)cont); setJTC((JTextComponent)cont);
} }
init(); init();
hasPicked = false; hasPicked = false;
} }
public DiacriticPanel(TibFrame tf) public DiacriticPanel(TibFrame tf)
{ {
this(false,tf); this(false,tf);
setFrame(tf); setFrame(tf);
setController(tf.getController()); setController(tf.getController());
} }
public DiacriticPanel(JTextComponent jtc) public DiacriticPanel(JTextComponent jtc)
{ {
this(true,jtc); this(true,jtc);
} }
// Inner Classes // Inner Classes
// The Mouse Adapter // The Mouse Adapter
/** /**
* <p> * <p>
* This inner class is a MouseAdapter that implements "mousePressed". It is added to a label with a diacritic * This inner class is a MouseAdapter that implements "mousePressed". It is added to a label with a diacritic
* so that when that label is clicked, the corresponding Unicode diacritic character is inserted in the * so that when that label is clicked, the corresponding Unicode diacritic character is inserted in the
* open document, a {@link TextPane}, at the cursor. * open document, a {@link TextPane}, at the cursor.
*</p> *</p>
*/ */
private class TiblEditMouseAdapter extends MouseAdapter private class TiblEditMouseAdapter extends MouseAdapter
{ {
/** /**
* <p> * <p>
* This version of mousePressed. Takes the {@link TibFrame} supplied with the DiacriticPanel's constructor * This version of mousePressed. Takes the {@link TibFrame} supplied with the DiacriticPanel's constructor
* and gets its {@link TextPane}. It then inserts the Unicode diacritic character from the source * and gets its {@link TextPane}. It then inserts the Unicode diacritic character from the source
* label at the cursor of this text pane. * label at the cursor of this text pane.
* </p> * </p>
*/ */
public void mousePressed(MouseEvent me) public void mousePressed(MouseEvent me)
{ {
TextPane tp = frame.getTextPane(); TextPane tp = frame.getTextPane();
if(tp.isEditable()) { if(tp.isEditable()) {
JLabel source = (JLabel)me.getSource(); JLabel source = (JLabel)me.getSource();
String dia = source.getText(); String dia = source.getText();
int pos = tp.getCaret().getDot(); int pos = tp.getCaret().getDot();
try { try {
tp.getDocument().insertString(pos,dia,tp.getCharacterAttributes()); tp.getDocument().insertString(pos,dia,tp.getCharacterAttributes());
} catch (BadLocationException ble) } catch (BadLocationException ble)
{ {
System.out.println("Bad location exception while inserting diacritic (" System.out.println("Bad location exception while inserting diacritic ("
+pos+")! \n"); +pos+")! \n");
} }
} }
} }
} }
private class GenMouseAdapter extends MouseAdapter private class GenMouseAdapter extends MouseAdapter
{ {
/** /**
* <p> * <p>
* This version of mousePressed. Takes the {@link TibFrame} supplied with the DiacriticPanel's constructor * This version of mousePressed. Takes the {@link TibFrame} supplied with the DiacriticPanel's constructor
* and gets its {@link TextPane}. It then inserts the Unicode diacritic character from the source * and gets its {@link TextPane}. It then inserts the Unicode diacritic character from the source
* label at the cursor of this text pane. * label at the cursor of this text pane.
* </p> * </p>
*/ */
public void mousePressed(MouseEvent me) public void mousePressed(MouseEvent me)
{ {
JLabel source = (JLabel)me.getSource(); JLabel source = (JLabel)me.getSource();
String dia = source.getText(); String dia = source.getText();
jtc.replaceSelection(dia); jtc.replaceSelection(dia);
} }
} }
// Main Method for testing // Main Method for testing
public static void main(String[] args) public static void main(String[] args)
{/* {/*
TibFrame tf = new TibFrame("Diacritic Test"); TibFrame tf = new TibFrame("Diacritic Test");
DiacriticPanel dp = new DiacriticPanel(); DiacriticPanel dp = new DiacriticPanel();
JScrollPane jsp = new JScrollPane(dp, JScrollPane jsp = new JScrollPane(dp,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
tf.setContentPane(jsp); tf.setContentPane(jsp);
tf.pack(); tf.pack();
tf.show();*/ tf.show();*/
} }
} }

View file

@ -39,7 +39,7 @@ public interface TibConstants
final String DATA_DIRECTORY = java.io.File.separatorChar + "data" + java.io.File.separatorChar; final String DATA_DIRECTORY = java.io.File.separatorChar + "data" + java.io.File.separatorChar;
final String OUT_DIRECTORY = java.io.File.separatorChar + "data" + java.io.File.separatorChar; final String OUT_DIRECTORY = java.io.File.separatorChar + "data" + java.io.File.separatorChar;
final String BIN_LOGIN = java.io.File.separatorChar + "bin" + java.io.File.separatorChar + "logs" + java.io.File.separatorChar; final String BIN_LOGIN = java.io.File.separatorChar + "bin" + java.io.File.separatorChar + "logs" + java.io.File.separatorChar;
final String DIA_DATA = java.io.File.separatorChar + "bin" + java.io.File.separatorChar + "dia.dat"; final String DIA_DATA = "dia.dat";
final String TEMP_DIR = java.io.File.separatorChar + "bin" + java.io.File.separatorChar + "temp" + java.io.File.separatorChar; final String TEMP_DIR = java.io.File.separatorChar + "bin" + java.io.File.separatorChar + "temp" + java.io.File.separatorChar;
final String PREFS = "ttprefs.ini"; final String PREFS = "ttprefs.ini";

View file

@ -0,0 +1,102 @@
0101
0100
0113
0112
012B
012A
014D
014C
016B
016A
1E0D
1E0C
1E25
1E24
1E37
1E36
1E39
1E38
1E43
1E42
1E47
1E46
1E5B
1E5A
1E5D
1E5C
1E63
1E62
1E6D
1E6C
1E93
1E92
1E41
1E40
1E45
1E44
00E4
00C4
00EB
00CB
00EF
00CF
00F6
00D6
00FC
00DC
00E3
00C3
1EBD
1EBC
0129
0128
00F1
00D1
00F5
00D5
0169
0168
00E1
00C1
00E9
00C9
00ED
00CD
00F3
00D3
015B
015A
00FA
00DA
00FD
00DD
017A
0179
00E0
00C0
00E8
00C8
00EC
00CC
00F2
00D2
00F9
00D9
00E2
00C2
00EA
00CA
00EE
00CE
00F4
00D4
00FB
00DB
00E7
00C7
015F
015E
0161
0160
017E
017D

View file

@ -5,7 +5,7 @@
@(#)package.html @(#)package.html
Copyright 2001-2003 Tibetan and Himalayan Digital Library Copyright 2001-2004 Tibetan and Himalayan Digital Library
This software is the confidential and proprietary information of This software is the confidential and proprietary information of
the Tibetan and Himalayan Digital Library. You shall use such the Tibetan and Himalayan Digital Library. You shall use such
@ -15,10 +15,11 @@
--> -->
</head> </head>
<body bgcolor="white"> <body bgcolor="white">
Provides classes and methods for the Tibbibl application. Provides classes and methods for the TiblEdit application.
<p> <p>
Tibbibl is for editing scholarly bibliographies of Tibetan texts, TiblEdit is for editing scholarly bibliographies of Tibetan texts,
where the bibliographies are stored as XML instances. where the bibliographies are stored as XML instances using the TIBBIBL
schema.
</p> </p>
</body> </body>
</html> </html>