📄 concepttypepropertyframe.java
字号:
package toocom.ui;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
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 type.
*
* @author Fr閐閞ic F黵st
*/
public class ConceptTypePropertyFrame extends JDialog implements ActionListener{
private ConceptType ct;
private MainFrame mf;
private GridBagLayout lay;
private GridBagConstraints gbc;
private JTextField termTextField;
private JComboBox languageMenu;
private JList parents;
private JList children;
private JCheckBox cb;
private JCheckBox cbP;
private JList disjointCT;
private LinkedList disConTypes;
private Language currentLanguage;
public ConceptTypePropertyFrame(ConceptType ct, MainFrame mf){
super(mf,Constants.PROPERTIES_OF_LABEL + ct.getTerm(mf.getOntologyLanguage()),true);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.mf = mf;
this.ct = ct;
currentLanguage = mf.getOntologyLanguage();
lay = new GridBagLayout();
this.getContentPane().setLayout(lay);
gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
// Term
Label lab = new Label(Constants.TERM_LABEL);
lay.setConstraints(lab,gbc);
this.getContentPane().add(lab);
termTextField = new JTextField(ct.getTerm(mf.getOntologyLanguage()));
lay.setConstraints(termTextField,gbc);
this.getContentPane().add(termTextField);
languageMenu = new JComboBox(Language.getAllLanguages().toArray());
languageMenu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setLanguage();
}
});
languageMenu.setSelectedItem(mf.getOntologyLanguage());
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(languageMenu,gbc);
this.getContentPane().add(languageMenu,gbc);
gbc.gridwidth = 1;
// Parents
lab = new Label(Constants.PARENTS_LABEL);
lay.setConstraints(lab,gbc);
this.getContentPane().add(lab);
String[] parentList = new String[ct.getParents().size()];
int cpt = 0;
for(Iterator i = ct.getParents().iterator();i.hasNext();){
parentList[cpt] = ((ConceptType) i.next()).getTerm(mf.getOntologyLanguage());
cpt ++;
}
parents = new JList(parentList);
parents.setVisibleRowCount(ct.getParents().size());
JScrollPane parentsScrollPane = new JScrollPane(parents);
gbc.weightx = 2.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(parentsScrollPane,gbc);
this.getContentPane().add(parentsScrollPane);
// Children
lab = new Label(Constants.CHILDREN_LABEL);
gbc.weightx = 1.0;
gbc.gridwidth = 1;
lay.setConstraints(lab,gbc);
this.getContentPane().add(lab);
String[] childrenList = new String[ct.getChildren().size()];
cpt = 0;
for(Iterator i = ct.getChildren().iterator();i.hasNext();){
childrenList[cpt] = ((ConceptType) i.next()).getTerm(mf.getOntologyLanguage());
cpt ++;
}
children = new JList(childrenList);
children.setVisibleRowCount(ct.getChildren().size());
JScrollPane childrenScrollPane = new JScrollPane(children);
gbc.weightx = 2.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(childrenScrollPane,gbc);
this.getContentPane().add(childrenScrollPane);
// Abstract
lab = new Label(Constants.ABSTRACT_LABEL);
gbc.weightx = 1.0;
gbc.gridwidth = 1;
lay.setConstraints(lab,gbc);
this.getContentPane().add(lab);
cb = new JCheckBox();
if(ct.hasAxiomSchema("toocom.ocgl.ConceptAbstraction")) cb.setSelected(true);
cb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setAbstract();
}
});
gbc.weightx = 1.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(cb,gbc);
this.getContentPane().add(cb);
// Partition
lab = new Label(Constants.PARTITION_LABEL);
gbc.weightx = 1.0;
gbc.gridwidth = 1;
lay.setConstraints(lab,gbc);
this.getContentPane().add(lab);
cbP = new JCheckBox();
if(ct.hasAxiomSchema("toocom.ocgl.ConceptPartition")) cbP.setSelected(true);
cbP.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setPartition();
}
});
gbc.weightx = 1.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(cbP,gbc);
this.getContentPane().add(cbP);
// Disjoint types
gbc.gridwidth = 1;
Box b = new Box(BoxLayout.Y_AXIS);
Label lab1 = new Label(Constants.DISJOINT_CONCEPT_TYPES_LABEL);
Label lab2 = new Label(Constants.USE_CTRL_KEY_LABEL);
b.add(lab1);
b.add(lab2);
lay.setConstraints(b,gbc);
this.getContentPane().add(b);
disConTypes = NamedObject.sortListByName(ConceptDisjunction.getLinkablePrimitives(mf.getOntology().getConceptTypes(),ct),mf.getOntologyLanguage());
disjointCT = new JList(new DefaultListModel());
disjointCT.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
disjointCT.setVisibleRowCount(Constants.DISJONCTION_LIST_VISIBLE_ROW_COUNT);
this.setDisjonction();
JScrollPane sp = new JScrollPane(disjointCT);
gbc.weightx = 2.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
lay.setConstraints(sp,gbc);
this.getContentPane().add(sp);
// OK button
JButton ok = new JButton(Constants.OK_LABEL);
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setValues();
}
});
gbc.weightx = 2.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();
}
private void setDisjonction(){
((DefaultListModel) disjointCT.getModel()).clear();
int cpt4 = 0;
for(Iterator i = disConTypes.iterator();i.hasNext();cpt4 ++){
ConceptType cTemp = (ConceptType) i.next();
((DefaultListModel) disjointCT.getModel()).addElement(cTemp.toString(mf.getOntologyLanguage()));
if(ct.hasAxiomSchemaTwo("toocom.ocgl.ConceptDisjunction",cTemp)) disjointCT.setSelectedIndex(cpt4);
}
}
public void setAbstract(){
if(cb.isSelected()) new ConceptAbstraction(ct);
else ct.removeAxiomSchemata("toocom.ocgl.ConceptAbstraction");
}
public void setPartition(){
if(cbP.isSelected()) new ConceptPartition(ct);
else ct.removeAxiomSchemata("toocom.ocgl.ConceptPartition");
}
public void setValues(){
Language l = (Language) languageMenu.getSelectedItem();
String term = termTextField.getText();
if(CGConstants.getUniversalTerms().getTerm(l).compareToIgnoreCase(term) == 0){
JOptionPane.showMessageDialog(mf,Constants.UNIVERSAL_LABEL_NOT_AUTHORIZED);
}
else{
ct.setTerm(term,l);
int[] indices = disjointCT.getSelectedIndices();
ct.removeAxiomSchemata("toocom.ocgl.ConceptDisjunction");
for(int cpt = 0;cpt < indices.length;cpt ++){
new ConceptDisjunction(ct,(ConceptType) disConTypes.get(indices[cpt]));
}
mf.getOntologySummaryFrame().refresh();
mf.repaint();
this.dispose();
}
}
public void setLanguage(){
ct.setTerm(termTextField.getText(),currentLanguage);
currentLanguage = (Language) languageMenu.getSelectedItem();
termTextField.setText(ct.getTerm(currentLanguage));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -