Made a new class for the preference window so that other software
(i.e. the translation tool) can use re-use that same code to set up the attributes of the tibetan and roman fonts.
This commit is contained in:
parent
ef0df405d9
commit
8e4b508de8
2 changed files with 135 additions and 71 deletions
|
@ -89,11 +89,11 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JComboBox fontFamilies, fontSizes;
|
// private JComboBox fontFamilies, fontSizes;
|
||||||
private JFileChooser fileChooser;
|
private JFileChooser fileChooser;
|
||||||
private javax.swing.filechooser.FileFilter rtfFilter;
|
private javax.swing.filechooser.FileFilter rtfFilter;
|
||||||
private javax.swing.filechooser.FileFilter txtFilter;
|
private javax.swing.filechooser.FileFilter txtFilter;
|
||||||
private int fontSize = 0;
|
// private int fontSize = 0;
|
||||||
private Object parentObject = null;
|
private Object parentObject = null;
|
||||||
private static int numberOfTibsRTFOpen = 0;
|
private static int numberOfTibsRTFOpen = 0;
|
||||||
private static int x_size;
|
private static int x_size;
|
||||||
|
@ -113,6 +113,8 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
*/
|
*/
|
||||||
public String fileName = null;
|
public String fileName = null;
|
||||||
|
|
||||||
|
private PreferenceWindow prefWindow;
|
||||||
|
|
||||||
/** the status bar for this frame */
|
/** the status bar for this frame */
|
||||||
private StatusBar statusBar;
|
private StatusBar statusBar;
|
||||||
|
|
||||||
|
@ -128,6 +130,13 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
/** Do not use this JPanel constructor. */
|
/** Do not use this JPanel constructor. */
|
||||||
private Jskad(LayoutManager lm, boolean isDB) { super(lm, isDB); }
|
private Jskad(LayoutManager lm, boolean isDB) { super(lm, isDB); }
|
||||||
|
|
||||||
|
/** Invokes to window to customize fonts. */
|
||||||
|
private void setPreferences()
|
||||||
|
{
|
||||||
|
if (prefWindow == null) prefWindow = new PreferenceWindow(this, dp);
|
||||||
|
prefWindow.show();
|
||||||
|
}
|
||||||
|
|
||||||
/** Saves user preferences to disk if possible. */
|
/** Saves user preferences to disk if possible. */
|
||||||
private void savePreferencesAction() {
|
private void savePreferencesAction() {
|
||||||
if (!clearedPrefs) {
|
if (!clearedPrefs) {
|
||||||
|
@ -380,7 +389,7 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
JMenuItem preferencesItem = new JMenuItem("Preferences");
|
JMenuItem preferencesItem = new JMenuItem("Preferences");
|
||||||
preferencesItem.addActionListener(new ThdlActionListener() {
|
preferencesItem.addActionListener(new ThdlActionListener() {
|
||||||
public void theRealActionPerformed(ActionEvent e) {
|
public void theRealActionPerformed(ActionEvent e) {
|
||||||
getPreferences();
|
setPreferences();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
editMenu.addSeparator();
|
editMenu.addSeparator();
|
||||||
|
@ -777,9 +786,8 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
keyboards.addActionListener(new ThdlActionListener() {
|
keyboards.addActionListener(new ThdlActionListener() {
|
||||||
public void theRealActionPerformed(ActionEvent e) {
|
public void theRealActionPerformed(ActionEvent e) {
|
||||||
int ki = keyboards.getSelectedIndex();
|
int ki = keyboards.getSelectedIndex();
|
||||||
keybdMgr.elementAt(keyboards.getSelectedIndex()).activate(dp);
|
keybdMgr.elementAt(ki).activate(dp);
|
||||||
ThdlOptions.setUserPreference("thdl.default.tibetan.keyboard",
|
ThdlOptions.setUserPreference("thdl.default.tibetan.keyboard", ki);
|
||||||
ki);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
toolBar.add(keyboards);
|
toolBar.add(keyboards);
|
||||||
|
@ -832,70 +840,6 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
add("South", statusBar);
|
add("South", statusBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getPreferences() {
|
|
||||||
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
||||||
String[] fontNames = genv.getAvailableFontFamilyNames();
|
|
||||||
|
|
||||||
JPanel tibetanPanel;
|
|
||||||
JComboBox tibetanFontSizes;
|
|
||||||
|
|
||||||
tibetanPanel = new JPanel();
|
|
||||||
tibetanPanel.setBorder(BorderFactory.createTitledBorder("Set Tibetan Font Size"));
|
|
||||||
tibetanFontSizes = new JComboBox(new String[] {"8","10","12","14","16","18","20","22","24","26","28","30","32","34","36","48","72"});
|
|
||||||
tibetanFontSizes.setMaximumSize(tibetanFontSizes.getPreferredSize());
|
|
||||||
tibetanFontSizes.setSelectedItem(String.valueOf(dp.getTibetanFontSize()));
|
|
||||||
tibetanFontSizes.setEditable(true);
|
|
||||||
tibetanPanel.add(tibetanFontSizes);
|
|
||||||
|
|
||||||
JPanel romanPanel;
|
|
||||||
JComboBox romanFontFamilies;
|
|
||||||
JComboBox romanFontSizes;
|
|
||||||
|
|
||||||
romanPanel = new JPanel();
|
|
||||||
romanPanel.setBorder(BorderFactory.createTitledBorder("Set non-Tibetan Font and Size"));
|
|
||||||
romanFontFamilies = new JComboBox(fontNames);
|
|
||||||
romanFontFamilies.setMaximumSize(romanFontFamilies.getPreferredSize());
|
|
||||||
romanFontFamilies.setSelectedItem(dp.getRomanFontFamily());
|
|
||||||
romanFontFamilies.setEditable(true);
|
|
||||||
romanFontSizes = new JComboBox(new String[] {"8","10","12","14","16","18","20","22","24","26","28","30","32","34","36","48","72"});
|
|
||||||
romanFontSizes.setMaximumSize(romanFontSizes.getPreferredSize());
|
|
||||||
romanFontSizes.setSelectedItem(String.valueOf(dp.getRomanFontSize()));
|
|
||||||
romanFontSizes.setEditable(true);
|
|
||||||
romanPanel.setLayout(new GridLayout(1,2));
|
|
||||||
romanPanel.add(romanFontFamilies);
|
|
||||||
romanPanel.add(romanFontSizes);
|
|
||||||
|
|
||||||
JPanel preferencesPanel = new JPanel();
|
|
||||||
preferencesPanel.setLayout(new GridLayout(2,1));
|
|
||||||
preferencesPanel.add(tibetanPanel);
|
|
||||||
preferencesPanel.add(romanPanel);
|
|
||||||
|
|
||||||
JOptionPane pane = new JOptionPane(preferencesPanel);
|
|
||||||
JDialog dialog = pane.createDialog(this, "Preferences");
|
|
||||||
|
|
||||||
// This returns only when the user has closed the dialog:
|
|
||||||
dialog.show();
|
|
||||||
|
|
||||||
int size;
|
|
||||||
try {
|
|
||||||
size = Integer.parseInt(tibetanFontSizes.getSelectedItem().toString());
|
|
||||||
dp.setByUserTibetanFontSize(size);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ne) {
|
|
||||||
size = dp.getTibetanFontSize();
|
|
||||||
dp.setTibetanFontSize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
String font = romanFontFamilies.getSelectedItem().toString();
|
|
||||||
try {
|
|
||||||
size = Integer.parseInt(romanFontSizes.getSelectedItem().toString());
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ne) {
|
|
||||||
size = dp.getRomanFontSize();
|
|
||||||
}
|
|
||||||
dp.setByUserRomanAttributeSet(font, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void newFile() {
|
private void newFile() {
|
||||||
if (dp.getDocument().getLength()>0 && parentObject instanceof JFrame) {
|
if (dp.getDocument().getLength()>0 && parentObject instanceof JFrame) {
|
||||||
JFrame parentFrame = (JFrame)parentObject;
|
JFrame parentFrame = (JFrame)parentObject;
|
||||||
|
|
120
source/org/thdl/tib/input/PreferenceWindow.java
Normal file
120
source/org/thdl/tib/input/PreferenceWindow.java
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
The contents of this file are subject to the THDL Open Community License
|
||||||
|
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License on the THDL web site
|
||||||
|
(http://www.thdl.org/).
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific terms governing rights and limitations under the
|
||||||
|
License.
|
||||||
|
|
||||||
|
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||||
|
Library (THDL). Portions created by the THDL are Copyright 2001-2003 THDL.
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s): ______________________________________.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.thdl.tib.input;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/** Shows a standard dialog window to set the preferences
|
||||||
|
for the tibetan and roman script used
|
||||||
|
*/
|
||||||
|
public class PreferenceWindow
|
||||||
|
{
|
||||||
|
private JDialog dialog;
|
||||||
|
private JComboBox tibetanFontSizes;
|
||||||
|
private JComboBox romanFontSizes;
|
||||||
|
private JComboBox romanFontFamilies;
|
||||||
|
private DuffPane dp;
|
||||||
|
|
||||||
|
public PreferenceWindow(Component parent, DuffPane dp)
|
||||||
|
{
|
||||||
|
this.dp = dp;
|
||||||
|
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
|
String[] fontNames = genv.getAvailableFontFamilyNames();
|
||||||
|
|
||||||
|
JPanel tibetanPanel;
|
||||||
|
|
||||||
|
tibetanPanel = new JPanel();
|
||||||
|
tibetanPanel.setBorder(BorderFactory.createTitledBorder("Set Tibetan Font Size"));
|
||||||
|
tibetanFontSizes = new JComboBox(new String[] {"8","10","12","14","16","18","20","22","24","26","28","30","32","34","36","48","72"});
|
||||||
|
tibetanFontSizes.setMaximumSize(tibetanFontSizes.getPreferredSize());
|
||||||
|
tibetanFontSizes.setSelectedItem(String.valueOf(dp.getTibetanFontSize()));
|
||||||
|
tibetanFontSizes.setEditable(true);
|
||||||
|
tibetanPanel.add(tibetanFontSizes);
|
||||||
|
|
||||||
|
JPanel romanPanel;
|
||||||
|
|
||||||
|
romanPanel = new JPanel();
|
||||||
|
romanPanel.setBorder(BorderFactory.createTitledBorder("Set non-Tibetan Font and Size"));
|
||||||
|
romanFontFamilies = new JComboBox(fontNames);
|
||||||
|
romanFontFamilies.setMaximumSize(romanFontFamilies.getPreferredSize());
|
||||||
|
romanFontFamilies.setSelectedItem(dp.getRomanFontFamily());
|
||||||
|
romanFontFamilies.setEditable(true);
|
||||||
|
romanFontSizes = new JComboBox(new String[] {"8","10","12","14","16","18","20","22","24","26","28","30","32","34","36","48","72"});
|
||||||
|
romanFontSizes.setMaximumSize(romanFontSizes.getPreferredSize());
|
||||||
|
romanFontSizes.setSelectedItem(String.valueOf(dp.getRomanFontSize()));
|
||||||
|
romanFontSizes.setEditable(true);
|
||||||
|
romanPanel.setLayout(new GridLayout(1,2));
|
||||||
|
romanPanel.add(romanFontFamilies);
|
||||||
|
romanPanel.add(romanFontSizes);
|
||||||
|
|
||||||
|
JPanel preferencesPanel = new JPanel();
|
||||||
|
preferencesPanel.setLayout(new GridLayout(2,1));
|
||||||
|
preferencesPanel.add(tibetanPanel);
|
||||||
|
preferencesPanel.add(romanPanel);
|
||||||
|
|
||||||
|
JOptionPane pane = new JOptionPane(preferencesPanel);
|
||||||
|
dialog = pane.createDialog(parent, "Preferences");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int stringToInt(String s)
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
num = Integer.parseInt(s);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ne) {
|
||||||
|
num = -1;
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTibetanFontSize()
|
||||||
|
{
|
||||||
|
return stringToInt(tibetanFontSizes.getSelectedItem().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRomanFontSize()
|
||||||
|
{
|
||||||
|
return stringToInt(romanFontSizes.getSelectedItem().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRomanFont()
|
||||||
|
{
|
||||||
|
return romanFontFamilies.getSelectedItem().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This returns only when the user has closed the dialog */
|
||||||
|
public void show()
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
String font;
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
|
||||||
|
size = getTibetanFontSize();
|
||||||
|
if (size>0) dp.setByUserTibetanFontSize(size);
|
||||||
|
|
||||||
|
size = getRomanFontSize();
|
||||||
|
if (size==-1) size = dp.getRomanFontSize();
|
||||||
|
font = getRomanFont();
|
||||||
|
dp.setByUserRomanAttributeSet(font, size);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue