📄 doublepanel.java
字号:
package risk.tools.translation;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.Box;
import javax.swing.JTree;
public class DoublePanel extends JPanel implements ActionListener {
private JLabel name;
private Mtcomm mycomm;
private MyNode message;
private JTree tree;
private YuraTextEditor top;
private YuraTextEditor bottom;
private Locale localetop;
private Locale localebottom;
public DoublePanel(JTree t) {
tree = t;
setLayout( new BorderLayout() );
name = new JLabel();
top = new YuraTextEditor();
bottom = new YuraTextEditor();
addButtons(top);
addButtons(bottom);
top.addActionListener(this);
bottom.addActionListener(this);
top.setLabel( "default" );
JPanel box2 = new JPanel( new GridLayout(2,1,10,10) );
box2.add(top);
box2.add(bottom);
box2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 10, 10, 10));
add(name,BorderLayout.NORTH);
add(box2);
}
private void addButtons(YuraTextEditor ytp) {
JButton save = new JButton("Save");
save.setActionCommand("save");
JButton revert = new JButton("Revert");
revert.setActionCommand("revert");
JButton setnull = new JButton("Remove");
setnull.setActionCommand("setnull");
ytp.add(save);
ytp.add(revert);
ytp.add(setnull);
}
public void reuse(MyNode a,Locale l1,Locale l2,Mtcomm com) throws Exception {
name.setText("<html><b> "+a.getName()+"</b></html>");
mycomm = com;
message = a;
localetop = l1;
top.setText( message.getMessage(mycomm,localetop) );
resetLocale(l2);
}
public void resetLocale(Locale a) throws Exception {
localebottom = a;
bottom.setLabel( "in "+localebottom );
bottom.setText( message.getMessage(mycomm,localebottom) );
}
public void revert() {
top.revert();
bottom.revert();
}
public boolean checkChange() {
return (
top.checkChange() ||
bottom.checkChange()
);
}
public void saveChanges() throws Exception {
saveChanges(top);
saveChanges(bottom);
}
public void setWrap(boolean a) {
top.setWrap(a);
bottom.setWrap(a);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("revert")) {
((YuraTextEditor)ae.getSource()).revert();
}
else if (ae.getActionCommand().equals("save")) {
try {
saveChanges( (YuraTextEditor)ae.getSource() );
}
catch(Exception e) {
showError( "unable to save: "+e.getMessage() );
}
tree.repaint();
}
else if (ae.getActionCommand().equals("setnull")) {
try {
if (ae.getSource() == top) {
message.saveMessage(mycomm, localetop, null ,localebottom);
top.setText( null );
}
else if (ae.getSource() == bottom) {
message.saveMessage(mycomm, localebottom, null ,localebottom);
bottom.setText( null );
}
tree.repaint();
}
catch(Exception e) {
showError( "unable to set to null: "+e.getMessage() );
}
}
else {
throw new RuntimeException( "unknown command "+ ae.getActionCommand() );
}
}
public void showError(String a) {
JOptionPane.showMessageDialog(this, a , "error!", JOptionPane.ERROR_MESSAGE );
}
public void saveChanges(YuraTextEditor a) throws Exception {
if ( a.checkChange() ) {
message.saveMessage(mycomm, (a == top)?(localetop):(localebottom), a.getText() ,localebottom);
// resets the background color to white
a.setText( a.getText() );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -