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