⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singlecomparisonpanel.java

📁 Java version of ABC/HR comparator v0.5. by schnofler. Runs on Sun JRE 1.5 or later
💻 JAVA
字号:
package abchr.gui;

import abchr.ComparisonGroup;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import jlfgr.GraphicsRepository;

public class SingleComparisonPanel extends JPanel {
	private ComparisonGroup compGroup;
	private JSlider[] sliders;
	private JTextField[] fields;
	private JButton[] commentButtons;

	private class CommentButtonAction extends AbstractAction implements CommentDialogListener {
		private int i;
		private CommentDialog dialog=null;
		public CommentButtonAction(int i) {
			super("Add Comments",GraphicsRepository.getToolbarIcon("general/Edit16.gif"));
			this.putValue(Action.SHORT_DESCRIPTION,"Add comments");
			this.i=i;
		}
		public void actionPerformed(ActionEvent e) {
			if(dialog==null){dialog=new CommentDialog();}
			dialog.showDialogModeless(compGroup.getComment(i),this);
		}
		public void dialogClosed(CommentDialog source,String text) {
			compGroup.setComment(i,text);
		}
	}

	public SingleComparisonPanel(String title,ComparisonGroup compGroup) {
		super(new GridBagLayout());
		GridBagConstraints constraints=new GridBagConstraints();
		this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),title,TitledBorder.CENTER,TitledBorder.DEFAULT_POSITION));
		this.compGroup=compGroup;
		compGroup.addListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e){changed(e);}
		});
		constraints.fill=GridBagConstraints.BOTH;
		constraints.insets=new Insets(0,1,2,1);
		constraints.gridx=GridBagConstraints.RELATIVE;constraints.gridy=0;
		commentButtons=new JButton[2];
		for(int i=0;i<2;i++) {
			commentButtons[i]=new JButton(new CommentButtonAction(i));
			commentButtons[i].setText("");
			commentButtons[i].setMargin(new Insets(2,4,2,4));
			commentButtons[i].setIconTextGap(0);
			commentButtons[i].setEnabled(false);
			this.add(commentButtons[i],constraints);
		}
		constraints.gridy=1;
		fields=new JTextField[2];
		for(int i=0;i<2;i++) {
			fields[i]=new JTextField("5.0",3);
			fields[i].setEditable(false);
			fields[i].setHorizontalAlignment(JTextField.CENTER);
			this.add(fields[i],constraints);
		}
		constraints.gridy=2;
		ChangeListener l=new ChangeListener() {
			public void stateChanged(ChangeEvent e){ratingChanged();}
		};
		sliders=new JSlider[2];
		for(int i=0;i<2;i++) {
			sliders[i]=new JSlider(JSlider.VERTICAL,10,50,50);
			sliders[i].setPreferredSize(new Dimension(20,150));
			sliders[i].setModel(compGroup.getRating(i));
			compGroup.getRating(i).addChangeListener(l);
			this.add(sliders[i],constraints);
		}
		constraints.gridy=3;
		JButton[] playButtons=new JButton[2];
		for(int i=0;i<2;i++) {
			playButtons[i]=new JButton(new PlayAction(compGroup.getSample(i),"Play Sample "+(i+1)+(i==0?" (q)":" (w)")));
			playButtons[i].setText("");
			playButtons[i].setMargin(new Insets(2,4,2,4));
			playButtons[i].setIconTextGap(0);
			this.add(playButtons[i],constraints);
		}
		constraints.gridy=4;
		JButton playRefButton=new JButton(new PlayAction(compGroup.getSample(compGroup.getOriginalIndex()),"Play Reference (e)"));
		playRefButton.setText("Ref");
		playRefButton.setMargin(new Insets(2,5,2,5));
		playRefButton.setIconTextGap(0);
		constraints.gridwidth=2;
		this.add(playRefButton,constraints);
		constraints.gridy=5;
		JButton stopButton=new JButton(new StopAction());
		stopButton.setToolTipText("Stop Playback (d)");
		stopButton.setText("Stop");
		stopButton.setMargin(new Insets(2,5,2,5));
		stopButton.setIconTextGap(0);
		this.add(stopButton,constraints);

		InputMap im=this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
		ActionMap am=this.getActionMap();
		im.put(KeyStroke.getKeyStroke('q'),"aButton");
		am.put("aButton",playButtons[0].getAction());
		im.put(KeyStroke.getKeyStroke('w'),"bButton");
		am.put("bButton",playButtons[1].getAction());
		im.put(KeyStroke.getKeyStroke('e'),"refButton");
		am.put("refButton",playRefButton.getAction());
		im.put(KeyStroke.getKeyStroke('d'),"stopButton");
		am.put("stopButton",stopButton.getAction());

		changed(null);
	}

	private void ratingChanged() {
		for(int i=0;i<2;i++) {
			commentButtons[i].setEnabled(compGroup.getRating(i).getValue()!=compGroup.getRating(i).getMaximum());
			fields[i].setText(Double.toString(compGroup.getRating(i).getValue()/10.0d));
		}
	}

	private void changed(ChangeEvent e) {
		if(compGroup.isBlind()) {
			sliders[0].setEnabled(true);
			sliders[1].setEnabled(true);
		} else {
			BoundedRangeModel r=compGroup.getRating(compGroup.getOriginalIndex());
			r.setValue(r.getMaximum());
			sliders[compGroup.getOriginalIndex()].setEnabled(false);
		}
		ratingChanged();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -