📄 conceptpropertyframe.java
字号:
package toocom.ui;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.lang.*;
import toocom.ocgl.*;
/**
* This class represents the graphical window used to specify the properties of a concept.
*
* @author Fr閐閞ic F黵st
*/
public class ConceptPropertyFrame extends JDialog implements ActionListener{
private Concept c;
private MainFrame mf;
private GridBagLayout lay;
private GridBagConstraints gbc;
private boolean inAxiom;
private int undefined;
private JComboBox conceptTypes;
private JComboBox indiv;
private JTextField termTextField;
private JButton hypConc;
private LinkedList ct;
private LinkedList in;
private Language currentLanguage;
/** Creates a ConceptPropertyFrame with a hypothesis/conclusion button if inAxiom is true,
* without this button elsewhere. */
public ConceptPropertyFrame(Concept c, MainFrame mf, boolean inAxiom){
super(mf,Constants.PROPERTIES_OF_LABEL + c.getTerm(mf.getOntologyLanguage()),true);
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.mf = mf;
this.c = c;
this.inAxiom = inAxiom;
currentLanguage = mf.getOntologyLanguage();
lay = new GridBagLayout();
this.getContentPane().setLayout(lay);
gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
// Concept types
Label lab = new Label(Constants.CONCEPT_TYPE_LABEL);
lay.setConstraints(lab,gbc);
this.getContentPane().add(lab);
conceptTypes = new JComboBox();
ct = NamedObject.sortListByName(mf.getOntology().getConceptTypes(),mf.getOntologyLanguage());
if(c.getType() == null){
conceptTypes.addItem("");
undefined = 1;
}
else undefined = 0;
for(Iterator i = ct.iterator();i.hasNext();){
ConceptType contype = (ConceptType) i.next();
conceptTypes.addItem(contype.toString(mf.getOntologyLanguage()));
if((c.getType() != null) && c.getType().equals(contype)) conceptTypes.setSelectedIndex(conceptTypes.getItemCount() - 1);
}
conceptTypes.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setType();
}
});
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(conceptTypes,gbc);
this.getContentPane().add(conceptTypes);
gbc.gridwidth = 1;
// Individuals
lab = new Label(Constants.ONTOLOGICAL_INSTANCE_LABEL);
lay.setConstraints(lab,gbc);
this.getContentPane().add(lab);
indiv = new JComboBox();
in = NamedObject.sortListByName(mf.getOntology().getIndividuals(c.getType()),mf.getOntologyLanguage());
if(c.getType() != null){
indiv.addItem(" ");
for(Iterator i = in.iterator();i.hasNext();){
Individual ibis = (Individual) i.next();
indiv.addItem(ibis.toString(mf.getOntologyLanguage()));
if(c.getIndividual() != null){
if(c.getIndividual().equals(ibis)) indiv.setSelectedIndex(indiv.getItemCount() - 1);
}
}
indiv.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setIndividual();
}
});
}
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(indiv,gbc);
this.getContentPane().add(indiv);
gbc.gridwidth = 1;
// Terms
if(!inAxiom){
lab = new Label(Constants.TERM_LABEL);
lay.setConstraints(lab,gbc);
this.getContentPane().add(lab);
if(c.getIndividual() == null) termTextField = new JTextField(c.getTerm(mf.getOntologyLanguage()));
else termTextField = new JTextField();
termTextField.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e){
setTerm();
}
public void focusLost(FocusEvent e){}
});
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(termTextField,gbc);
this.getContentPane().add(termTextField);
}
// Hypothesis/Conclusion
if(inAxiom){
hypConc = new JButton(Constants.HYPOTHESIS_CONCEPT_LABEL);
if(mf.getAxiomsFrame().getCurrentAxiom().hasPureConclusionConcept(c)) hypConc.setText(Constants.CONCLUSION_CONCEPT_LABEL);
hypConc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setHypConc();
}
});
gbc.weightx = 1.0;
gbc.gridx = 0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(hypConc,gbc);
this.getContentPane().add(hypConc);
}
JButton ok = new JButton(Constants.OK_LABEL);
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setValues();
}
});
gbc.weightx = 1.0;
gbc.gridx = 0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(ok,gbc);
this.getContentPane().add(ok);
this.pack();
this.setLocation((mf.getWidth() - this.getWidth())/2,(mf.getHeight() - this.getHeight())/2);
this.getRootPane().registerKeyboardAction(this,"ok",KeyStroke.getKeyStroke(Constants.OK_KEY),JComponent.WHEN_IN_FOCUSED_WINDOW);
this.setVisible(true);
this.toFront();
}
public void actionPerformed(ActionEvent event){
if(event.getActionCommand().equals("ok")) this.setValues();
}
public void processWindowEvent(WindowEvent e){
if(e.getID() == WindowEvent.WINDOW_CLOSING) this.setValues();
}
public void setValues(){
if(inAxiom){
if(mf.getAxiomsFrame().getCurrentAxiom().hasPureConclusionConcept(c) && hypConc.getText().equals(Constants.HYPOTHESIS_CONCEPT_LABEL)){
mf.getAxiomsFrame().getCurrentAxiom().convertInHypothesis(c);
}
if(mf.getAxiomsFrame().getCurrentAxiom().hasHypothesisConcept(c) && hypConc.getText().equals(Constants.CONCLUSION_CONCEPT_LABEL)){
mf.getAxiomsFrame().getCurrentAxiom().convertInConclusion(c);
}
}
if(!inAxiom && !termTextField.getText().equals("")){
c.setIndividual(null);
c.setTerm(termTextField.getText(),mf.getOntologyLanguage());
}
mf.repaint();
this.dispose();
}
public void setTerm(){
if(indiv.getItemCount() > 0) this.indiv.setSelectedIndex(0);
c.setIndividual(null);
this.repaint();
}
public void setType(){
if((conceptTypes.getSelectedIndex() == 0) && (undefined == 1)){
c.setType(null);
indiv.removeAllItems();
this.repaint();
}
else{
ConceptType conType = (ConceptType) ct.get(conceptTypes.getSelectedIndex() - undefined);
c.setType(conType);
in.clear();
indiv.removeAllItems();
indiv.addItem(" ");
for(Iterator i = mf.getOntology().getIndividuals(conType).iterator();i.hasNext();){
in.add(i.next());
indiv.addItem(((Individual) in.getLast()).toString(mf.getOntologyLanguage()));
if(c.getIndividual() != null){
if(c.getIndividual().equals((Individual) in.getLast())) indiv.setSelectedIndex(indiv.getItemCount() - 1);
}
}
indiv.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setIndividual();
}
});
this.repaint();
}
}
public void setIndividual(){
if(indiv.getSelectedIndex() > 0){
c.setIndividual((Individual) in.get(indiv.getSelectedIndex() - 1));
if(!inAxiom) termTextField.setText("");
}
else c.setIndividual(null);
}
public void setHypConc(){
if(hypConc.getText().equals(Constants.HYPOTHESIS_CONCEPT_LABEL)){
hypConc.setText(Constants.CONCLUSION_CONCEPT_LABEL);
}
else hypConc.setText(Constants.HYPOTHESIS_CONCEPT_LABEL);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -