desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/KukTopComponent.java
2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
19 package cz.xelfi.quoridor.desktop.sample;
21 import cz.xelfi.quoridor.webidor.Game;
22 import org.openide.util.NbBundle;
23 import org.openide.windows.TopComponent;
24 //import org.openide.util.ImageUtilities;
25 import org.netbeans.api.settings.ConvertAsProperties;
28 * Top component which displays the board.
30 @ConvertAsProperties(dtd = "-//cz.xelfi.quoridor.desktop.sample//Kuk//EN",
32 public final class KukTopComponent extends TopComponent {
34 /** path to the icon used by the component and its open action */
35 // static final String ICON_PATH = "SET/PATH/TO/ICON/HERE";
36 private static final String PREFERRED_ID = "KukTopComponent";
40 public KukTopComponent() {
44 public void setGameId(String id) {
46 final Game g = Quoridor.getDefault().getGame(id);
47 boardPane1.setBoard(g.getBoard());
49 NbBundle.getMessage(KukTopComponent.class, "CTL_KukTopComponent",
50 g.getId().getWhite(), g.getId().getBlack()
54 NbBundle.getMessage(KukTopComponent.class, "HINT_KukTopComponent",
55 g.getId().getWhite(), g.getId().getBlack()
60 /** This method is called from within the constructor to
61 * initialize the form.
62 * WARNING: Do NOT modify this code. The content of this method is
63 * always regenerated by the Form Editor.
65 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
66 private void initComponents() {
68 jLabel1 = new javax.swing.JLabel();
69 boardPane1 = new cz.xelfi.quoridor.visidor.BoardPane();
70 jButton1 = new javax.swing.JButton();
71 jButton2 = new javax.swing.JButton();
73 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(KukTopComponent.class, "KukTopComponent.jLabel1.text")); // NOI18N
75 jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/xelfi/quoridor/desktop/sample/black.png"))); // NOI18N
76 org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(KukTopComponent.class, "KukTopComponent.jButton1.text")); // NOI18N
77 jButton1.addActionListener(new java.awt.event.ActionListener() {
78 public void actionPerformed(java.awt.event.ActionEvent evt) {
79 jButton1ActionPerformed(evt);
83 jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/xelfi/quoridor/desktop/sample/white.png"))); // NOI18N
84 org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getMessage(KukTopComponent.class, "KukTopComponent.jButton2.text")); // NOI18N
85 jButton2.addActionListener(new java.awt.event.ActionListener() {
86 public void actionPerformed(java.awt.event.ActionEvent evt) {
87 jButton2ActionPerformed(evt);
91 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
92 this.setLayout(layout);
93 layout.setHorizontalGroup(
94 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
95 .addGroup(layout.createSequentialGroup()
96 .addComponent(jButton1)
97 .addContainerGap(225, Short.MAX_VALUE))
98 .addGroup(layout.createSequentialGroup()
99 .addComponent(jButton2)
101 .addComponent(boardPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
103 layout.setVerticalGroup(
104 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
105 .addGroup(layout.createSequentialGroup()
106 .addComponent(jButton1)
107 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
108 .addComponent(boardPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
109 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
110 .addComponent(jButton2))
112 }// </editor-fold>//GEN-END:initComponents
114 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
116 }//GEN-LAST:event_jButton2ActionPerformed
118 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
120 }//GEN-LAST:event_jButton1ActionPerformed
122 // Variables declaration - do not modify//GEN-BEGIN:variables
123 private cz.xelfi.quoridor.visidor.BoardPane boardPane1;
124 private javax.swing.JButton jButton1;
125 private javax.swing.JButton jButton2;
126 private javax.swing.JLabel jLabel1;
127 // End of variables declaration//GEN-END:variables
130 public int getPersistenceType() {
131 return TopComponent.PERSISTENCE_ALWAYS;
135 public void componentOpened() {
136 // TODO add custom code on component opening
140 public void componentClosed() {
141 // TODO add custom code on component closing
144 void writeProperties(java.util.Properties p) {
145 // better to version settings since initial version as advocated at
146 // http://wiki.apidesign.org/wiki/PropertyFiles
147 p.setProperty("version", "1.0");
149 p.setProperty("id", id);
153 final void readProperties(java.util.Properties p) {
154 String version = p.getProperty("version");
155 String myId = p.getProperty("id");
162 protected String preferredID() {