desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/KukTopComponent.java
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package cz.xelfi.quoridor.desktop.sample;
7 import cz.xelfi.quoridor.webidor.Game;
8 import org.openide.util.NbBundle;
9 import org.openide.windows.TopComponent;
10 //import org.openide.util.ImageUtilities;
11 import org.netbeans.api.settings.ConvertAsProperties;
14 * Top component which displays the board.
16 @ConvertAsProperties(dtd = "-//cz.xelfi.quoridor.desktop.sample//Kuk//EN",
18 public final class KukTopComponent extends TopComponent {
20 /** path to the icon used by the component and its open action */
21 // static final String ICON_PATH = "SET/PATH/TO/ICON/HERE";
22 private static final String PREFERRED_ID = "KukTopComponent";
26 public KukTopComponent() {
30 public void setGameId(String id) {
32 final Game g = Quoridor.getDefault().getGame(id);
33 boardPane1.setBoard(g.getBoard());
35 NbBundle.getMessage(KukTopComponent.class, "CTL_KukTopComponent",
36 g.getId().getWhite(), g.getId().getBlack()
40 NbBundle.getMessage(KukTopComponent.class, "HINT_KukTopComponent",
41 g.getId().getWhite(), g.getId().getBlack()
46 /** This method is called from within the constructor to
47 * initialize the form.
48 * WARNING: Do NOT modify this code. The content of this method is
49 * always regenerated by the Form Editor.
51 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
52 private void initComponents() {
54 jLabel1 = new javax.swing.JLabel();
55 boardPane1 = new cz.xelfi.quoridor.visidor.BoardPane();
56 jButton1 = new javax.swing.JButton();
57 jButton2 = new javax.swing.JButton();
59 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(KukTopComponent.class, "KukTopComponent.jLabel1.text")); // NOI18N
61 jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/xelfi/quoridor/desktop/sample/black.png"))); // NOI18N
62 org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(KukTopComponent.class, "KukTopComponent.jButton1.text")); // NOI18N
63 jButton1.addActionListener(new java.awt.event.ActionListener() {
64 public void actionPerformed(java.awt.event.ActionEvent evt) {
65 jButton1ActionPerformed(evt);
69 jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/xelfi/quoridor/desktop/sample/white.png"))); // NOI18N
70 org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getMessage(KukTopComponent.class, "KukTopComponent.jButton2.text")); // NOI18N
71 jButton2.addActionListener(new java.awt.event.ActionListener() {
72 public void actionPerformed(java.awt.event.ActionEvent evt) {
73 jButton2ActionPerformed(evt);
77 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
78 this.setLayout(layout);
79 layout.setHorizontalGroup(
80 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
81 .addGroup(layout.createSequentialGroup()
82 .addComponent(jButton1)
83 .addContainerGap(225, Short.MAX_VALUE))
84 .addGroup(layout.createSequentialGroup()
85 .addComponent(jButton2)
87 .addComponent(boardPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
89 layout.setVerticalGroup(
90 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
91 .addGroup(layout.createSequentialGroup()
92 .addComponent(jButton1)
93 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
94 .addComponent(boardPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
95 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
96 .addComponent(jButton2))
98 }// </editor-fold>//GEN-END:initComponents
100 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
102 }//GEN-LAST:event_jButton2ActionPerformed
104 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
106 }//GEN-LAST:event_jButton1ActionPerformed
108 // Variables declaration - do not modify//GEN-BEGIN:variables
109 private cz.xelfi.quoridor.visidor.BoardPane boardPane1;
110 private javax.swing.JButton jButton1;
111 private javax.swing.JButton jButton2;
112 private javax.swing.JLabel jLabel1;
113 // End of variables declaration//GEN-END:variables
116 public int getPersistenceType() {
117 return TopComponent.PERSISTENCE_ALWAYS;
121 public void componentOpened() {
122 // TODO add custom code on component opening
126 public void componentClosed() {
127 // TODO add custom code on component closing
130 void writeProperties(java.util.Properties p) {
131 // better to version settings since initial version as advocated at
132 // http://wiki.apidesign.org/wiki/PropertyFiles
133 p.setProperty("version", "1.0");
135 p.setProperty("id", id);
139 final void readProperties(java.util.Properties p) {
140 String version = p.getProperty("version");
141 String myId = p.getProperty("id");
148 protected String preferredID() {