📄 localeconfiguration.java
字号:
m_RootNode.remove(current);
m_Model.reload();
this.repaint();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public void addLocale(String name, int index) {
LocaleTreeNode newLocale = new LocaleTreeNode(name);
m_RootNode.insert(newLocale, index);
m_Model.reload();
this.repaint();
}
private void buildTree() {
String[] names = LocalesManager.getLocalesNames();
LocaleTreeNode parentNode = null;
for (int i = 0; i < names.length; i++) {
parentNode = new LocaleTreeNode(names[i]);
m_RootNode.add(parentNode);
}
m_Model.setRoot(m_RootNode);
}
private void init() {
this.setSelectionRow(0);
}
private void reset() {
this.setSelectionRow(Localeconfiguration.getCurrentIndex());
}
private MouseAdapter TreeMouseListener() {
return new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
TreePath path = getPathForLocation(e.getX(), e.getY());
if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON3) {
// show popupmenu
if (path == null) {
Localeconfiguration.setFarFromTree(true);
Localepopupmenu.setStyle(LocalePopupMenu.ADD);
Localepopupmenu.setLocation(new Point(e.getX(), e.getY()));
Localepopupmenu.show((Component) e.getSource(), e.getX(), e.getY());
} else {
Localeconfiguration.setFarFromTree(false);
Localepopupmenu.setStyle(LocalePopupMenu.ADD_DELETE);
Localepopupmenu.setLocation(new Point(e.getX(), e.getY()));
Localepopupmenu.show((Component) e.getSource(), e.getX(), e.getY());
}
} else if (e.getButton() == MouseEvent.BUTTON1) {
if (path != null) {
LocaleTreeNode Localetreenode = (LocaleTreeNode) path.getLastPathComponent();
if (m_RootNode.getIndex(Localetreenode) == Localeconfiguration.getCurrentIndex()) {
return;
}
int index = Localeconfiguration.getCurrentIndex();
if (!Localeconfiguration.setCurrent(m_RootNode.getIndex(Localetreenode))) {
reset();
} else {
if (Localeconfiguration.isNew()) {
if (Localeconfiguration.getCountofLocale() < m_RootNode.getChildCount()) {
removeLocale(index);
}
}
}
}
}
}
};
}
/**
* Xiaojun Chen. July 12, 2006.
*
* @see javax.swing.event.TreeSelectionListener#valueChanged(TreeSelectionEvent)
*/
public void valueChanged(TreeSelectionEvent e) {
}
}
class LocaleInformation extends JPanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private LocaleConfiguration Localeconfiguration;
private JScrollPane detailScrollPanel;
private JPanel detailPanel;
private JLabel nameLabel;
private JLabel jarfileLabel;
private JLabel charsetLabel;
private JLabel descriptionLabel;
private JTextField nameText;
private JTextField fileText;
private JTextField charsetName;
private JTextArea descriptionText;
private JPanel buttonPanel;
private JButton m_ButtonApply;
private JButton m_ButtonClose;
private locale Locale;
LocaleInformation(LocaleConfiguration Localeconfiguration) {
super();
this.Localeconfiguration = Localeconfiguration;
createUI();
}
private void createUI() {
createDetailPanel();
createButtonPanel();
this.add(detailScrollPanel, BorderLayout.CENTER);
this.add(buttonPanel, BorderLayout.SOUTH);
}
private void createDetailPanel() {
detailScrollPanel = new JScrollPane();
detailPanel = new JPanel();
detailPanel.setLayout(new GridLayout(4, 2, 5, 10));
detailPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Resource
.srcStr("LocaleInformation")), BorderFactory.createEmptyBorder(2, 0, 0, 0)));
nameLabel = new JLabel(Resource.srcStr("LocaleConfiguration_name"));
jarfileLabel = new JLabel(Resource.srcStr("LocaleConfiguration_jarfilename"));
charsetLabel = new JLabel(Resource.srcStr("LocaleConfiguration_charset"));
descriptionLabel = new JLabel(Resource.srcStr("LocaleConfiguration_description"));
// nameLabel.setFont(new Font("宋体",Font.PLAIN,19));
// pathLabel.setFont(new Font("宋体",Font.PLAIN,19));
// descriptionLabel.setFont(new Font("宋体",Font.PLAIN,19));
nameText = new JTextField();
fileText = new JTextField();
charsetName = new JTextField();
descriptionText = new JTextArea();
nameText.setPreferredSize(new Dimension(135, 25));
nameText.setEditable(false);
fileText.setPreferredSize(new Dimension(135, 25));
fileText.setEditable(false);
charsetName.setPreferredSize(new Dimension(135, 25));
charsetName.setEditable(false);
descriptionText.setPreferredSize(new Dimension(135, 25));
descriptionText.setEditable(false);
JPanel namePanel = new JPanel();
namePanel.add(nameLabel, BorderLayout.WEST);
namePanel.add(nameText, BorderLayout.CENTER);
JPanel pathPanel = new JPanel();
pathPanel.add(jarfileLabel, BorderLayout.WEST);
pathPanel.add(fileText, BorderLayout.CENTER);
JPanel charsetPanel = new JPanel();
charsetPanel.add(charsetLabel, BorderLayout.WEST);
charsetPanel.add(charsetName, BorderLayout.CENTER);
JPanel descriptionPanel = new JPanel();
descriptionPanel.add(descriptionLabel, BorderLayout.WEST);
descriptionPanel.add(descriptionText, BorderLayout.CENTER);
//detailPanel.add(namePanel);
//detailPanel.add(pathPanel);
//detailPanel.add(charsetPanel);
//detailPanel.add(descriptionPanel);
detailPanel.add(nameLabel);
detailPanel.add(nameText);
detailPanel.add(jarfileLabel);
detailPanel.add(fileText);
detailPanel.add(charsetLabel);
detailPanel.add(charsetName);
detailPanel.add(descriptionLabel);
detailPanel.add(descriptionText);
detailScrollPanel.getViewport().add(detailPanel);
}
private void createButtonPanel() {
buttonPanel = new JPanel(new GridLayout(1, 3, 10, 5));
m_ButtonApply = new JButton(Resource.srcStr("m_ButtonImport"));
m_ButtonClose = new JButton(Resource.srcStr("m_ButtonClose"));
buttonPanel.add(m_ButtonApply);
buttonPanel.add(m_ButtonClose);
m_ButtonApply.addActionListener(this);
m_ButtonClose.addActionListener(this);
}
public void resetLocale() {
((TitledBorder)((CompoundBorder)detailPanel.getBorder()).getOutsideBorder()).setTitle(Resource
.srcStr("LocaleInformation"));
nameLabel.setText(Resource.srcStr("LocaleConfiguration_name"));
jarfileLabel.setText(Resource.srcStr("LocaleConfiguration_jarfilename"));
charsetLabel.setText(Resource.srcStr("LocaleConfiguration_charset"));
descriptionLabel.setText(Resource.srcStr("LocaleConfiguration_description"));
m_ButtonApply.setText(Resource.srcStr("m_ButtonImport"));
m_ButtonClose.setText(Resource.srcStr("m_ButtonClose"));
}
public void getContent() {
locale Locale = Localeconfiguration.getCurrentLocale();
if (Locale == null || !Locale.isvalid()) {
return;
}
this.Locale = Locale;
nameText.setText(Locale.getName());
fileText.setText(Locale.getFile());
charsetName.setText(Locale.getCharsetName());
descriptionText.setText(Locale.getDescription());
if(Localeconfiguration.isNew()) {
m_ButtonApply.setEnabled(true);
}
else {
m_ButtonApply.setEnabled(false);
}
}
public void getContent(locale Locale) {
if (Locale == null || !Locale.isvalid()) {
return;
}
this.Locale = Locale;
nameText.setText(Locale.getName());
fileText.setText(Locale.getFile());
charsetName.setText(Locale.getCharsetName());
descriptionText.setText(Locale.getDescription());
if(Localeconfiguration.isNew()) {
m_ButtonApply.setEnabled(true);
}
else {
m_ButtonApply.setEnabled(false);
}
}
// save content to Locales
public void setContent() {
if(!Localeconfiguration.isNew()){
return;
}
if (!Localeconfiguration.saveLocale()) {
MessageDialog.showMessageDialog(Localeconfiguration, Resource.srcStr("Locale_ImportFailure"));
}
}
public boolean clear() {
nameText.setText("");
fileText.setText("");
descriptionText.setText("");
return true;
}
public locale getCurrentLocale() {
return Locale;
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == m_ButtonApply) {
setContent();
} else if (source == m_ButtonClose) {
Localeconfiguration.close();
}
}
}
class LocaleTreeNode extends DefaultMutableTreeNode {
/**
*
*/
private static final long serialVersionUID = 1L;
public LocaleTreeNode(String name) {
super(name);
}
}
class LocalePopupMenu extends JPopupMenu implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final int ADD_DELETE = 0;
public static final int ADD = 1;
private JMenuItem m_MenuImport = new JMenuItem();
private JMenuItem m_MenuDelete = new JMenuItem();
private LocaleConfiguration Localeconfiguration;
public LocalePopupMenu(LocaleConfiguration Localeconfiguration) {
super();
this.Localeconfiguration = Localeconfiguration;
createMenu();
}
private void createMenu() {
m_MenuImport.setText(Resource.srcStr("Localepopupmenu_Import"));
m_MenuDelete.setText(Resource.srcStr("Localepopupmenu_Delete"));
m_MenuImport.addActionListener(this);
m_MenuDelete.addActionListener(this);
add(m_MenuImport);
}
public void setStyle(int style) {
switch (style) {
case ADD_DELETE:
add(m_MenuDelete);
break;
case ADD:
remove(m_MenuDelete);
break;
}
}
public void resetLocale() {
m_MenuImport.setText(Resource.srcStr("Localepopupmenu_Import"));
m_MenuDelete.setText(Resource.srcStr("Localepopupmenu_Delete"));
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == m_MenuImport) {
if (!Localeconfiguration.ImportLocale()) {
MessageDialog.showMessageDialog(Localeconfiguration, Resource.srcStr("Locale_ImportFailure"));
}
} else if (source == m_MenuDelete) {
Localeconfiguration.deleteLocale();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -