📄 ratingscalesetuppanel.java
字号:
package abchr.gui;
import abchr.RatingScaleModule;
import guiutils.FlexibleGridLayout;
import guiutils.LineLayout;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RatingScaleSetupPanel extends JPanel {
private class ConfigureRatingsDialog extends JDialog {
private JTextField[] labels=new JTextField[5];
public ConfigureRatingsDialog(Dialog owner) {
super(owner,"Configure Rating Scale Labels",true);
Container cp=this.getContentPane();
cp.setLayout(new BorderLayout());
JPanel centerPanel=new JPanel(new FlexibleGridLayout(5,2));
centerPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
for(int i=4;i>=0;i--) {
centerPanel.add(new JLabel((i+1)+".0 = "));
centerPanel.add(labels[i]=new JTextField(20));
}
cp.add(centerPanel,BorderLayout.CENTER);
JPanel bottomPanel=new JPanel(new LineLayout(LineLayout.RIGHT_ALIGN));
bottomPanel.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
JButton okButton=new JButton("OK");
JButton cancelButton=new JButton("Cancel");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(int i=0;i<5;i++) {
ratings[i]=labels[i].getText();
//testConfig.setRatingScaleLabel(i,labels[i].getText());
}
hide();
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){hide();}
});
bottomPanel.add(cancelButton);
bottomPanel.add(okButton);
cp.add(bottomPanel,BorderLayout.SOUTH);
}
public void show() {
Dimension size=this.getContentPane().getPreferredSize();
Insets insets=getOwner().getInsets();
this.setBounds(getOwner().getX()+10,getOwner().getY()+10,size.width+insets.left+insets.right,size.height+insets.top+insets.bottom);
for(int i=0;i<5;i++){labels[i].setText(ratings[i]);}
super.show();
}
}
private RatingScaleModule ratingScaleModule;
private ConfigureRatingsDialog ratingsDialog;
private JCheckBox customRatingsCheckBox=new JCheckBox("Custom labels for rating scale",false);
private JButton configureRatingsButton=new JButton("Configure...");
private String[] ratings=new String[]{"","","","",""};
public RatingScaleSetupPanel(Dialog owner) {
ratingsDialog=new ConfigureRatingsDialog(owner);
this.setLayout(new LineLayout(LineLayout.LEFT_ALIGN,true));
configureRatingsButton.setEnabled(false);
configureRatingsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ratingsDialog.show();
if(customRatingsCheckBox.isSelected()) {
for(int i=0;i<5;i++){ratingScaleModule.setRatingScaleLabel(i,ratings[i]);}
} else {
for(int i=0;i<5;i++){ratingScaleModule.setRatingScaleLabel(i,null);}
}
}
});
customRatingsCheckBox.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
configureRatingsButton.setEnabled(customRatingsCheckBox.isSelected());
if(customRatingsCheckBox.isSelected()) {
for(int i=0;i<5;i++){ratingScaleModule.setRatingScaleLabel(i,ratings[i]);}
} else {
for(int i=0;i<5;i++){ratingScaleModule.setRatingScaleLabel(i,null);}
}
}
});
this.add(customRatingsCheckBox);
this.add(configureRatingsButton);
}
public void setModel(RatingScaleModule model) {
ratingScaleModule=model;
ratings=ratingScaleModule.getRatingScale();
boolean deactivate=true;
for(int i=0;i<5;i++) {
if(ratings[i]!=null){deactivate=false;break;}
}
if(deactivate) {
customRatingsCheckBox.setSelected(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -