View Javadoc

1   /* $Id: EditorDesktopTextBasedGames.java 30 2013-04-27 18:40:17Z mihlon $ */
2   
3   //////////////////////////////////////////////////////////////////////////////
4   //                                                                          //
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, or      //
8   //   at your option any later version.                                      //
9   //                                                                          //
10  //   This program is distributed in the hope that it will be useful,        //
11  //   but WITHOUT ANY WARRANTY; without even the implied warranty of         //
12  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          //
13  //   GNU General Public License for more details.                           //
14  //                                                                          //
15  //   You should have received a copy of the GNU General Public License      //
16  //   along with this program.  If not, see <http://www.gnu.org/licenses/>.  //
17  //                                                                          //
18  //////////////////////////////////////////////////////////////////////////////
19  
20  package cs.pancava.caltha.desktop;
21  
22  import cs.pancava.caltha.EditorComponentListener;
23  import cs.pancava.caltha.graphics.EditorGraphicsWorld2D;
24  import cs.pancava.caltha.menu.World2DPopupMenuListener;
25  import java.awt.BorderLayout;
26  import java.awt.Dimension;
27  import java.awt.Toolkit;
28  import java.awt.event.MouseListener;
29  import javax.swing.JPanel;
30  import javax.swing.JScrollPane;
31  import javax.swing.JSplitPane;
32  import javax.swing.ScrollPaneConstants;
33  
34  /**
35   * <p><b>Tato trida definuje vzhled editoru pro textove hry.</b></p>
36   *
37   * @author Milan Vaclavik<br />
38   * @version $Revision: 30 $<br />
39   * $LastChangedBy: mihlon $<br />
40   */
41  public class EditorDesktopTextBasedGames extends EditorDesktop
42  {
43      /**
44       * Identifikace tridy - datum vzniku tridy :).
45       */
46      private static final long serialVersionUID = 20080731165138L;
47  
48      /**
49       * Minimalni velikost (sirka) okna, na kterou lze okno zmensit.
50       */
51      private static final int MINIMUM_SIZE_SCROLL_PANE_WIDTH_I = 100;
52  
53      /**
54       * Minimalni velikost (vyska) okna, na kterou lze okno zmensit.
55       */
56      private static final int MINIMUM_SIZE_SCROLL_PANE_HEIGHT_I = 50;
57  
58      /**
59       * Urcuje velikost (vysku) panelu v % pro vytvareni sveta a zobrazeni jeho
60       * atributu.
61       */
62      private static final double HEIGHT_WA_SPLIT_PANE_D = 0.80;
63  
64      /**
65       * Obsahuje hlavni okna editoru, u kterych se da libovolne menit velikost.
66       * Vsechna okna jsou navzajem spojena - zmena velikosti jednoho okna ovlivni
67       * velikost jineho okna.
68       */
69      private JSplitPane dektop;
70  
71      /**
72       * Panel pro zobrazovani vlastnosti jednotlivych atributu RPG sveta.
73       */
74      private JScrollPane propertiesScrollPane;
75  
76      /**
77       * SplitPane obekt, ktery obsahuje okno pro vytvareni RPG sveta a okno
78       * pro zobrazovani atributu RPG sveta.
79       */
80      private WorldAttributeSplitPane waSplitPane;
81  
82      /**
83       * Konstruktor - vytvori zakladni plochu editoru pro textove hry.
84       */
85      public EditorDesktopTextBasedGames()
86      {
87          super(EditorDesktop.EDITOR_TEXT_BASED_GAMES);
88      }
89  
90      /**
91       * Vytvori zakladni plochu pro dany typ editoru.
92       */
93      @Override
94      public final void createDesktop()
95      {
96          // Vytvoreni panelu pro vlozeni jednotlivych oken editoru.
97          this.setMainDesktop(new JPanel(new BorderLayout()));
98          this.getMainDesktop().setOpaque(true);
99  
100         //Create an instance of WorldAttributeSplitPane
101         this.waSplitPane = new WorldAttributeSplitPane();
102         final JSplitPane top = this.waSplitPane.getSplitPane();
103 
104         // XXXX: Bug #4131528, borders on nested split panes accumulate.
105         // Workaround: Set the border on any split pane within
106         // another split pane to null. Components within nested split
107         // panes need to have their own border for this to work well.
108         top.setBorder(null);
109 
110         this.propertiesScrollPane = new JScrollPane();
111 
112         this.dektop = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
113                                      top,
114                                      this.propertiesScrollPane);
115         this.dektop.setOneTouchExpandable(true);
116 
117         // Nastaveni minimalni velikosti oken.
118         top.setMinimumSize(new Dimension(EditorDesktopTextBasedGames.MINIMUM_SIZE_SCROLL_PANE_WIDTH_I,
119                                          EditorDesktopTextBasedGames.MINIMUM_SIZE_SCROLL_PANE_HEIGHT_I));
120         this.propertiesScrollPane.setMinimumSize(new Dimension(EditorDesktopTextBasedGames.MINIMUM_SIZE_SCROLL_PANE_WIDTH_I,
121                                                                EditorDesktopTextBasedGames.MINIMUM_SIZE_SCROLL_PANE_HEIGHT_I));
122 
123         this.getMainDesktop().add(this.dektop, BorderLayout.CENTER);
124 
125         // Registrace posluchace, ktery reaguje na zmenu hlavniho okna
126         this.getMainDesktop().addComponentListener(new EditorComponentListener(this));
127 
128         this.validate();
129     }
130 
131     /**
132      * Nastavi rozmery hlavnich oken na pevne dane hodnoty, ktere jsou
133      * procentualne nastavene.
134      */
135     @Override
136     public final void resizeWin()
137     {
138         this.dektop.setDividerLocation((int) (this.getMainDesktop().getSize().height * EditorDesktopTextBasedGames.HEIGHT_WA_SPLIT_PANE_D));
139 
140         this.waSplitPane.resizeWin(this.getMainDesktop().getSize().width);
141 
142         this.validate();
143     }
144 }
145 
146 /**
147  * Tato trida definuje vzhled programu - definuje rozvrzeni oken pro tvorbu
148  * sveta a zobrazeni jeho atributu.
149  *
150  * @author Milan Vaclavik
151  * @version $Revision: 30 $
152  * $LastChangedBy: mihlon $
153  */
154 class WorldAttributeSplitPane extends JPanel
155 {
156     /**
157      * Identifikace tridy - datum vzniku tridy :).
158      */
159     private static final long serialVersionUID = 20080430223333L;
160 
161     /**
162      * Minimalni velikost (sirka) okna, na kterou lze okno zmensit.
163      */
164     private static final int MINIMUM_SIZE_SCROLL_PANE_WIDTH_I = 100;
165 
166     /**
167      * Minimalni velikost (vyska) okna, na kterou lze okno zmensit.
168      */
169     private static final int MINIMUM_SIZE_SCROLL_PANE_HEIGHT_I = 50;
170 
171     /**
172      * Urcuje velikost (sirku) okna, ktere se sklada z komponent pro
173      * vytvareni sveta a zobrazovani jeho atributu.
174      */
175     private static final int WA_SPLIT_PANE_WIDTH = 800;
176 
177     /**
178      * Urcuje velikost (vysku) okna, ktere se sklada z komponent pro
179      * vytvareni sveta a zobrazovani jeho atributu.
180      */
181     private static final int WA_SPLIT_PANE_HEIGHT = 600;
182 
183     /**
184      * Urcuje velikost (sirku) panelu v % pro vytvareni sveta a zobrazeni jeho
185      * atributu.
186      */
187     private static final double WIDTH_WORLD_SCROLL_PANE_D = 0.80;
188 
189     /**
190      * Panel, kde se vytvari vlastni svet.
191      */
192     private EditorGraphicsWorld2D graphicsWorld2D;
193 
194     /**
195      * Panel pro zobrazovani atributu jednotlivych casti sveta.
196      */
197     private JScrollPane attributeScrollPane;
198 
199     /**
200      * Panel obsahujici okna pro vytvareni sveta a zobrazovani jeho atributu.
201      */
202     private JSplitPane waSplitPane;
203 
204     /**
205      * Konstruktor, ktery vytvari panel pro zobrazeni oken pro vytvareni
206      * sveta a zobrazovani jeho atributu.
207      */
208     public WorldAttributeSplitPane()
209     {
210         this.graphicsWorld2D     = new EditorGraphicsWorld2D();
211         this.attributeScrollPane = new JScrollPane();
212 
213         //Put the drawing area in a scroll pane.
214         // Vytvoreni scrollovaci plochy
215         JScrollPane scroller = new JScrollPane(this.graphicsWorld2D, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
216 
217         this.waSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
218                                           scroller,
219                                           this.attributeScrollPane);
220 
221         this.waSplitPane.setOneTouchExpandable(true);
222 
223         // Nastaveni minimalni velikosti oken.
224         final Dimension minimumSize = new Dimension(WorldAttributeSplitPane.MINIMUM_SIZE_SCROLL_PANE_WIDTH_I,
225                                                     WorldAttributeSplitPane.MINIMUM_SIZE_SCROLL_PANE_HEIGHT_I);
226 
227         // Ve vychozim stavu nastavime velokost plochy podle velikosti obrazovky, aby se pocitalo rovnou s celou oblasti,
228         // kdyz postrani panely zcela minimalizujeme
229         this.graphicsWorld2D.setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
230 
231         this.attributeScrollPane.setMinimumSize(minimumSize);
232 
233         // Preferovana velikost okna
234         this.waSplitPane.setPreferredSize(new Dimension(WorldAttributeSplitPane.WA_SPLIT_PANE_WIDTH,
235                                                         WorldAttributeSplitPane.WA_SPLIT_PANE_HEIGHT));
236 
237         this.createWorldPopupMenu();
238     }
239 
240     /**
241      * Vrati referenci na panel, ktery se sklada ze dvou oken (pro vytvareni
242      * sveta a zobrazovani jeho atributu).
243      * @return JSplitPane : Panel obsahujici dve okna (pro vytvareni
244      * sveta a zobrazovani jeho atributu).
245      */
246     protected JSplitPane getSplitPane()
247     {
248         return this.waSplitPane;
249     }
250 
251     /**
252      * Nastavi rozmery hlavnich oken na pevne dane hodnoty, ktere jsou
253      * procentualne nastavene. K vypoctu je treba znat skutecnou (vychozi) sirku
254      * okna a procentualni vyjardreni nove hodnoty.
255      * @param widthI int : Skutecna (vychozi) sirka okna.
256      */
257     public void resizeWin(final int widthI)
258     {
259         this.waSplitPane.setDividerLocation((int) (widthI * WorldAttributeSplitPane.WIDTH_WORLD_SCROLL_PANE_D));
260     }
261 
262     /**
263      * Vytvori popup menu.
264      */
265     private void createWorldPopupMenu()
266     {
267         final MouseListener popupListener = new World2DPopupMenuListener(this.graphicsWorld2D);
268         this.graphicsWorld2D.addMouseListener(popupListener);
269     }
270 }