package cz.muni.fi.bronchus.gui;
/*
* PropertiesDialog.java
*
* Created on May 18, 2004, 1:59 PM
*/
import cz.muni.fi.bronchus.questions.*;
import javax.swing.*;
import java.awt.Color;
import java.util.Vector;
import javax.swing.text.html.*;
import java.awt.*;
/**
*
* @author xudrzal
*/
public class PropertiesDialog extends MyCentralizedJDialog {
private static final Color Button_Highlight_COLOR = new Color(153, 153, 204);
private static final Color Button_Normal_COLOR = new Color(212, 208, 200);
public static int OK_OPTION=0;
public static int MODIFY_OPTION=1;
public static int DELETE_OPTION=2;
public static int MOVE_OPTION=3;
public static int USEASBASIS_OPTION=4;
public static int SHOW_RESPROCESSING=5;
private int selected=-1;
private MyUtilities myUtilities;
private MyResources myResources;
/** Creates new form PropertiesDialog */
public PropertiesDialog(java.awt.Frame parent, boolean modal, MyResources res) {
super(parent, modal);
myResources = res;
initComponents();
myInitComponents();
myUtilities=new MyUtilities(myResources);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
setTitle(myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle", "Properties"));
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel1.setBorder(new javax.swing.border.EtchedBorder());
jPanel1.setMaximumSize(new java.awt.Dimension(400, 300));
jPanel1.setMinimumSize(new java.awt.Dimension(400, 300));
jPanel1.setPreferredSize(new java.awt.Dimension(400, 300));
jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 290));
jTextPane1.setEnabled(false);
jScrollPane1.setViewportView(jTextPane1);
jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(5, 5, 290, -1));
jButton1.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.focus"));
jButton1.setFont(new java.awt.Font("Dialog", 0, 11));
jButton1.setText(myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle", "OK"));
jButton1.setPreferredSize(new java.awt.Dimension(83, 25));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 20, 90, -1));
jButton2.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.focus"));
jButton2.setFont(new java.awt.Font("Dialog", 0, 11));
jButton2.setText(myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle", "Modify"));
jButton2.setPreferredSize(new java.awt.Dimension(83, 24));
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 70, 90, -1));
jButton3.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.focus"));
jButton3.setFont(new java.awt.Font("Dialog", 0, 11));
jButton3.setText(myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle", "Delete"));
jButton3.setPreferredSize(new java.awt.Dimension(83, 24));
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanel1.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 100, 90, -1));
jButton4.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.focus"));
jButton4.setFont(new java.awt.Font("Dialog", 0, 11));
jButton4.setText(myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle", "Move"));
jButton4.setPreferredSize(new java.awt.Dimension(83, 24));
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jPanel1.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 130, 90, -1));
jButton5.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.focus"));
jButton5.setFont(new java.awt.Font("Dialog", 0, 11));
jButton5.setText(myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle", "
Use as basis"));
jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton5.setMargin(new java.awt.Insets(2, 2, 2, 2));
jButton5.setPreferredSize(new java.awt.Dimension(83, 25));
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jPanel1.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 180, 90, 40));
jButton6.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.focus"));
jButton6.setFont(new java.awt.Font("Dialog", 0, 11));
jButton6.setText(myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle", "Show Resprocessing"));
jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton6.setMargin(new java.awt.Insets(2, 2, 2, 2));
jButton6.setPreferredSize(new java.awt.Dimension(83, 25));
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jPanel1.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 230, 90, 40));
getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
pack();
}//GEN-END:initComponents
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
selected=5;
setVisible(false);
dispose();
}//GEN-LAST:event_jButton6ActionPerformed
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// Add your handling code here:
selected=4;
setVisible(false);
dispose();
}//GEN-LAST:event_jButton5ActionPerformed
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// Add your handling code here:
selected=3;
setVisible(false);
dispose();
}//GEN-LAST:event_jButton4ActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// Add your handling code here:
if (myUtilities.showAnswerDialog(this,myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle","Delete_Question"),
myResources.getBundle("cz/muni/fi/bronchus/bundles/PropertiesDialogBundle","Do_you_really_want_to_remove_this_item?"))==JOptionPane.YES_OPTION) {
selected=2;
setVisible(false);
dispose();
}
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// Add your handling code here:
selected=1;
setVisible(false);
dispose();
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// Add your handling code here:
selected=0;
setVisible(false);
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
selected=-1;
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
public int showDialog() {
setVisible(true);
return selected;
}
public void isModifying(boolean a) {
if (a) {
jButton2.setBackground(Button_Normal_COLOR);
jButton3.setBackground(Button_Normal_COLOR);
jButton4.setBackground(Button_Normal_COLOR);
jButton5.setBackground(Button_Normal_COLOR);
jButton6.setBackground(Button_Normal_COLOR);
} else {
jButton2.setBackground(Button_Highlight_COLOR);
jButton3.setBackground(Button_Highlight_COLOR);
jButton4.setBackground(Button_Highlight_COLOR);
jButton5.setBackground(Button_Highlight_COLOR);
jButton6.setBackground(Button_Highlight_COLOR);
}
jButton2.setEnabled(!a);
jButton3.setEnabled(!a);
jButton4.setEnabled(!a);
jButton5.setEnabled(!a);
jButton6.setEnabled(!a);
}
private void setHTMLKit(JTextPane textpane, String begin, boolean wholecontent) {
HTMLDocument doc;
HTMLEditorKit htmlKit;
StyleSheet styleSheet = new StyleSheet();
styleSheet.addRule("body {font-family: Dialog; font-size: 11pt; font-style: normal; font-weight: normal;}");
htmlKit = new HTMLEditorKit();
htmlKit.setDefaultCursor(new Cursor(Cursor.TEXT_CURSOR));
htmlKit.setStyleSheet(styleSheet);
doc = (HTMLDocument) htmlKit.createDefaultDocument();
textpane.setEditorKit(htmlKit);
textpane.setDocument(doc);
textpane.setMargin(new Insets(0, 0, 0, 0));
textpane.setContentType("text/html");
if (wholecontent)
textpane.setText(begin);
else
textpane.setText(""+begin+"
");
textpane.setCaretPosition(doc.getLength());
}
public void loadQuestion(Question q) {
String output=myUtilities.getQuestionBaseInfo(q);
output+=myUtilities.getQuestionFeedbacksInfo(q);
output+=myUtilities.getQuestionResprocessingInfo(q);
setHTMLKit(jTextPane1, output, false);
}
private void myInitComponents() {
// jTextArea1.setFont(new java.awt.Font("Dialog", 0, 11));
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
Question q=new TrueFalseQuestion();
new PropertiesDialog(new javax.swing.JFrame(), true, null).setVisible(true);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextPane jTextPane1;
// End of variables declaration//GEN-END:variables
}