Merge /pub/main
[educational.data.git] / Dr.NO / src / drno / swingui / guiView / ColorChooser.java
blob7b67a4354b0b049973ca2fd8e20f05250e2ae885
1 /*
2 * ColorChooser.java
4 * Created on 11. maj 2005, 13:20
5 */
7 package drno.swingui.guiView;
9 import java.awt.Color;
10 import java.awt.Component;
11 import java.awt.Dimension;
12 import java.awt.Rectangle;
13 import java.awt.event.ActionListener;
15 import javax.swing.ListSelectionModel;
16 import javax.swing.event.ListSelectionEvent;
17 import javax.swing.event.ListSelectionListener;
19 /**
21 * @author Leo
23 public class ColorChooser extends javax.swing.JFrame {
24 String selectedBackgroundElement = "";
25 String selectedForegroundElement = "";
26 /** Creates new form ColorChooser */
27 public ColorChooser() {
28 initComponents();
31 /** This method is called from within the constructor to
32 * initialize the form.
33 * WARNING: Do NOT modify this code. The content of this method is
34 * always regenerated by the Form Editor.
36 private void initComponents() {//GEN-BEGIN:initComponents
37 jPanel1 = new javax.swing.JPanel();
38 jButton2 = new javax.swing.JButton();
39 jColorChooser1 = new javax.swing.JColorChooser();
40 jButton1 = new javax.swing.JButton();
41 jButton3 = new javax.swing.JButton();
42 jScrollPane1 = new javax.swing.JScrollPane();
43 jList1 = new javax.swing.JList();
44 jLabel1 = new javax.swing.JLabel();
45 jScrollPane2 = new javax.swing.JScrollPane();
46 jList2 = new javax.swing.JList();
47 jLabel2 = new javax.swing.JLabel();
49 getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
50 setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
51 jPanel1.setLayout(null);
53 jButton2.setText("OK");
54 jButton2.addActionListener(new java.awt.event.ActionListener() {
55 public void actionPerformed(java.awt.event.ActionEvent evt) {
56 jButton2ActionPerformed(evt);
58 });
60 jPanel1.add(jButton2);
61 jButton2.setBounds(300, 360, 80, 23);
63 jPanel1.add(jColorChooser1);
64 jColorChooser1.setBounds(190, 0, 409, 333);
66 jButton1.setText("Annuller");
67 jButton1.addActionListener(new java.awt.event.ActionListener() {
68 public void actionPerformed(java.awt.event.ActionEvent evt) {
69 jButton1ActionPerformed(evt);
71 });
73 jPanel1.add(jButton1);
74 jButton1.setBounds(400, 360, 80, 23);
76 jButton3.setText("Anvend");
77 jButton3.addActionListener(new java.awt.event.ActionListener() {
78 public void actionPerformed(java.awt.event.ActionEvent evt) {
79 jButton3ActionPerformed(evt);
81 });
83 jPanel1.add(jButton3);
84 jButton3.setBounds(500, 360, 80, 23);
86 jList1.setModel(new javax.swing.AbstractListModel() {
87 String[] strings = { "Tabel", "Infomation", "Ansat", "Tidsreservation", "JCalendar","ProgressBar","Knapper","Label","Menu" };
88 public int getSize() { return strings.length; }
89 public Object getElementAt(int i) { return strings[i]; }
90 });
91 ListSelectionModel LSM1 = jList1.getSelectionModel();
92 LSM1.addListSelectionListener(new ListSelectionListener() {
93 public void valueChanged(ListSelectionEvent e) {
94 //Ignore extra messages.
95 if (e.getValueIsAdjusting()) return;
97 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
98 if (lsm.isSelectionEmpty()) {
99 selectedBackgroundElement = "";
100 //System.out.println("No rows are selected.");
102 else {
103 jList2.clearSelection();
104 selectedBackgroundElement = (String)jList1.getSelectedValue();
105 //System.out.println(selectedBackgroundElement);
106 //System.out.println(selectedForegroundElement);
110 jScrollPane1.setViewportView(jList1);
112 jPanel1.add(jScrollPane1);
113 jScrollPane1.setBounds(10, 40, 170, 120);
115 jLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 11));
116 jLabel1.setText("Baggrund:");
117 jPanel1.add(jLabel1);
118 jLabel1.setBounds(10, 20, 110, 20);
120 jList2.setModel(new javax.swing.AbstractListModel() {
121 String[] strings = { "Tabel", "Infomation", "Ansat", "Tidsreservation", "Knapper", "Menu", "JCalendar","Label","ProgressBar" };
122 public int getSize() { return strings.length; }
123 public Object getElementAt(int i) { return strings[i]; }
125 ListSelectionModel LSM2 = jList2.getSelectionModel();
126 LSM2.addListSelectionListener(new ListSelectionListener() {
127 public void valueChanged(ListSelectionEvent e) {
128 //Ignore extra messages.
129 if (e.getValueIsAdjusting()) return;
131 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
132 if (lsm.isSelectionEmpty()) {
133 selectedForegroundElement = "";
134 //System.out.println("No rows are selected.");
136 else {
137 jList1.clearSelection();
138 selectedForegroundElement = (String)jList2.getSelectedValue();
139 //System.out.println(selectedBackgroundElement);
140 //System.out.println(selectedForegroundElement);
144 jScrollPane2.setViewportView(jList2);
146 jPanel1.add(jScrollPane2);
147 jScrollPane2.setBounds(10, 190, 170, 140);
149 jLabel2.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 11));
150 jLabel2.setText("Text:");
151 jPanel1.add(jLabel2);
152 jLabel2.setBounds(10, 170, 110, 20);
154 getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 597, 410));
156 pack();
158 Dimension dim = getToolkit().getScreenSize();
159 Rectangle rec = getBounds();
160 int x = dim.width/2-rec.width/2;
161 int y = dim.height/2-rec.height/2;
162 setLocation(x,y);
163 }//GEN-END:initComponents
165 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
166 // TODO add your handling code here:
167 }//GEN-LAST:event_jButton3ActionPerformed
169 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
170 // TODO add your handling code here:
171 }//GEN-LAST:event_jButton2ActionPerformed
173 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
174 //jTable1.setBackground(jColorChooser1.getColor());
175 }//GEN-LAST:event_jButton1ActionPerformed
178 * @param args the command line arguments
180 public static void main(String args[]) {
181 java.awt.EventQueue.invokeLater(new Runnable() {
182 public void run() {
183 new ColorChooser().setVisible(true);
188 // Variables declaration - do not modify//GEN-BEGIN:variables
189 private javax.swing.JButton jButton1;
190 private javax.swing.JButton jButton2;
191 private javax.swing.JButton jButton3;
192 private javax.swing.JColorChooser jColorChooser1;
193 private javax.swing.JLabel jLabel1;
194 private javax.swing.JLabel jLabel2;
195 private javax.swing.JList jList1;
196 private javax.swing.JList jList2;
197 private javax.swing.JPanel jPanel1;
198 private javax.swing.JScrollPane jScrollPane1;
199 private javax.swing.JScrollPane jScrollPane2;
200 // End of variables declaration//GEN-END:variables
202 //ActionListners:
203 public void setOKListener(ActionListener listener) {
204 jButton2.addActionListener(listener);
206 public void setAnnullerListener(ActionListener listener) {
207 jButton1.addActionListener(listener);
209 public void setAnvendListener(ActionListener listener) {
210 jButton3.addActionListener(listener);
213 //get- set- Metoder til ColorChooser:
214 public Color getChoosedColor(){
215 return jColorChooser1.getColor();
217 public String getList1Element(){
218 return selectedBackgroundElement;
220 public String getList2Element(){
221 return selectedForegroundElement;