📄 instancepropertyframe.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 an instance
* of concept type.
*
* @author Fr閐閞ic F黵st
*/
public class InstancePropertyFrame extends JDialog implements ActionListener{
private MainFrame mf;
private JTextField termTextField;
private JComboBox languageMenu;
private JComboBox conceptTypes;
private LinkedList ct;
private Language currentLanguage;
private Individual i;
/** Putting the instance variable to null creates a new Instance in the ontology. */
public InstancePropertyFrame(MainFrame mf,Individual instance){
super(mf,Constants.INSTANCE_CREATION_FRAME_TITLE,true);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.mf = mf;
if(instance == null) this.i = mf.getOntology().newIndividual(Terms.getUndefinedTerms(),ConceptType.getUndefinedConceptType());
else this.i = instance;
currentLanguage = mf.getOntologyLanguage();
Box all = new Box(BoxLayout.Y_AXIS);
this.getContentPane().add(all);
Box terms = new Box(BoxLayout.X_AXIS);
Box type = new Box(BoxLayout.X_AXIS);
all.add(type);
all.add(terms);
type.add(new Label(Constants.CONCEPT_TYPE_LABEL));
conceptTypes = new JComboBox();
ct = NamedObject.sortListByName(mf.getOntology().getConceptTypes(),mf.getOntologyLanguage());
LinkedList temp = new LinkedList();
for(Iterator i = ct.iterator();i.hasNext();){
ConceptType conType = (ConceptType) i.next();
if(!conType.hasAxiomSchema("toocom.ocgl.ConceptAbstraction")){
temp.add(conType);
conceptTypes.addItem(conType.toString(mf.getOntologyLanguage()));
if(conType.equals(this.i.getType())) conceptTypes.setSelectedIndex(conceptTypes.getItemCount() - 1);
}
}
ct = temp;
type.add(conceptTypes);
terms.add(new Label(Constants.TERM_LABEL));
termTextField = new JTextField();
termTextField.setText(i.getTerm(mf.getOntologyLanguage()));
terms.add(termTextField);
languageMenu = new JComboBox(Language.getAllLanguages().toArray());
languageMenu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setLanguage();
}
});
languageMenu.setSelectedItem(mf.getOntologyLanguage());
terms.add(languageMenu);
if(instance != null){
JButton remove = new JButton(Constants.REMOVE_INSTANCE_LABEL);
//remove.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
//remove.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
remove.setBorder(BorderFactory.createRaisedBevelBorder());
remove.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
removeInstance();
}
});
all.add(remove);
}
JButton ok = new JButton(Constants.OK_LABEL);
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setValues();
}
});
all.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(){
Language l = (Language) languageMenu.getSelectedItem();
String term = termTextField.getText();
if(Terms.getGenericConceptTerms().getTerm(l).compareToIgnoreCase(term) == 0){
JOptionPane.showMessageDialog(mf,Constants.GENERIC_LABEL_NOT_AUTHORIZED);
}
else{
i.setTerm(term,l);
i.setType((ConceptType) ct.get(conceptTypes.getSelectedIndex()));
TooCoMMutableTreeNode omtn = mf.getOntologySummaryFrame().getInstanceNode(this.i);
mf.repaint();
mf.getOntologySummaryFrame().refresh();
this.dispose();
}
}
public void setLanguage(){
i.setTerm(termTextField.getText(),currentLanguage);
currentLanguage = (Language) languageMenu.getSelectedItem();
termTextField.setText(i.getTerm(currentLanguage));
}
public void removeInstance(){
mf.getOntology().removeIndividual(this.i);
mf.getOntologySummaryFrame().refresh();
mf.repaint();
this.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -