| 1 21 22 package org.opensubsystems.core.application.swt; 23 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.graphics.Cursor; 26 import org.eclipse.swt.graphics.Font; 27 import org.eclipse.swt.graphics.FontData; 28 import org.eclipse.swt.graphics.Image; 29 import org.eclipse.swt.widgets.Button; 30 import org.eclipse.swt.widgets.Combo; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Display; 33 import org.eclipse.swt.widgets.Label; 34 import org.eclipse.swt.widgets.List; 35 import org.eclipse.swt.widgets.Shell; 36 import org.eclipse.swt.widgets.TabFolder; 37 import org.eclipse.swt.widgets.Table; 38 import org.eclipse.swt.widgets.Text; 39 import org.opensubsystems.core.util.GlobalConstants; 40 41 49 public class ResourceManager 50 { 51 53 56 private static final String IMPL_LOCK = "IMPL_LOCK"; 57 58 61 public static final int MIDDLE_BUTTON_FONT_HEIGHT = 14; 62 63 66 public static final int BIG_BUTTON_FONT_HEIGHT = 22; 67 68 71 public static final int MIDDLE_TEXT_FONT_HEIGHT = 14; 72 73 76 public static final int BIG_TEXT_FONT_HEIGHT = 22; 77 78 81 public static final int BIG_TABLE_FONT_HEIGHT = 20; 82 83 86 public static final int BIG_COMBO_FONT_HEIGHT = 20; 87 88 91 public static final int BIG_LIST_FONT_HEIGHT = 20; 92 93 96 public static final int BIG_TAB_FOLDER_FONT_HEIGHT = 20; 97 98 100 103 private static ResourceManager s_defaultInstance; 104 105 107 110 protected Font m_middleButtonFont = null; 111 112 115 protected Font m_bigButtonFont = null; 116 117 120 protected Font m_bigTextFont = null; 121 122 125 protected Font m_bigTableFont = null; 126 127 130 protected Font m_bigComboFont = null; 131 132 135 protected Font m_bigListFont = null; 136 137 140 protected Font m_middleLabelFont = null; 141 142 145 protected Font m_bigLabelFont = null; 146 147 150 protected Font m_bigTabFolderFont = null; 151 152 155 protected Cursor m_waitCursor = null; 156 157 160 protected Cursor m_defaultCursor = null; 161 162 165 protected Image m_blankImage = null; 166 167 169 174 public static ResourceManager getInstance( 175 ) 176 { 177 if (s_defaultInstance == null) 178 { 179 synchronized (IMPL_LOCK) 182 { 183 if (s_defaultInstance == null) 184 { 185 setInstance(new ResourceManager()); 186 } 187 } 188 } 189 190 return s_defaultInstance; 191 } 192 193 200 public static void setInstance( 201 ResourceManager defaultInstance 202 ) 203 { 204 if (GlobalConstants.ERROR_CHECKING) 205 { 206 207 assert defaultInstance != null : "Default instance cannot be null"; 208 } 209 210 synchronized (IMPL_LOCK) 211 { 212 s_defaultInstance = defaultInstance; 213 } 214 } 215 216 219 public void releaseResources( 220 ) 221 { 222 if ((m_middleButtonFont != null) && (!m_middleButtonFont.isDisposed())) 223 { 224 m_middleButtonFont.dispose(); 225 m_middleButtonFont = null; 226 } 227 if ((m_bigButtonFont != null) && (!m_bigButtonFont.isDisposed())) 228 { 229 m_bigButtonFont.dispose(); 230 m_bigButtonFont = null; 231 } 232 if ((m_bigTextFont != null) && (!m_bigTextFont.isDisposed())) 233 { 234 m_bigTextFont.dispose(); 235 m_bigTextFont = null; 236 } 237 if ((m_bigTableFont != null) && (!m_bigTableFont.isDisposed())) 238 { 239 m_bigTableFont.dispose(); 240 m_bigTableFont = null; 241 } 242 if ((m_bigComboFont != null) && (!m_bigComboFont.isDisposed())) 243 { 244 m_bigComboFont.dispose(); 245 m_bigComboFont = null; 246 } 247 if ((m_bigListFont != null) && (!m_bigListFont.isDisposed())) 248 { 249 m_bigListFont.dispose(); 250 m_bigListFont = null; 251 } 252 if ((m_middleLabelFont != null) && (!m_middleLabelFont.isDisposed())) 253 { 254 m_middleLabelFont.dispose(); 255 m_middleLabelFont = null; 256 } 257 if ((m_bigLabelFont != null) && (!m_bigLabelFont.isDisposed())) 258 { 259 m_bigLabelFont.dispose(); 260 m_bigLabelFont = null; 261 } 262 if ((m_bigTabFolderFont != null) && (!m_bigTabFolderFont.isDisposed())) 263 { 264 m_bigTabFolderFont.dispose(); 265 m_bigTabFolderFont = null; 266 } 267 if ((m_waitCursor != null) && (!m_waitCursor.isDisposed())) 268 { 269 m_waitCursor.dispose(); 270 m_waitCursor = null; 271 } 272 if ((m_defaultCursor != null) && (!m_defaultCursor.isDisposed())) 273 { 274 m_defaultCursor.dispose(); 275 m_defaultCursor = null; 276 } 277 if ((m_blankImage != null) && (!m_blankImage.isDisposed())) 278 { 279 m_blankImage.dispose(); 280 m_blankImage = null; 281 } 282 } 283 284 289 public void setMiddleButtonFont( 290 Button middleButton 291 ) 292 { 293 if (m_middleButtonFont == null) 294 { 295 Font initialFont = middleButton.getFont(); 296 FontData[] fontData = initialFont.getFontData(); 297 for (int i = 0; i < fontData.length; i++) 298 { 299 fontData[i].setHeight(MIDDLE_BUTTON_FONT_HEIGHT); 300 } 301 m_middleButtonFont = new Font(middleButton.getDisplay(), fontData); 302 } 303 middleButton.setFont(m_middleButtonFont); 304 } 305 306 311 public void setBigTabFolderFont( 312 TabFolder bigTabFolder 313 ) 314 { 315 if (m_bigTabFolderFont == null) 316 { 317 Font initialFont = bigTabFolder.getFont(); 318 FontData[] fontData = initialFont.getFontData(); 319 for (int i = 0; i < fontData.length; i++) 320 { 321 fontData[i].setHeight(BIG_TAB_FOLDER_FONT_HEIGHT); 322 } 323 m_bigTabFolderFont = new Font(bigTabFolder.getDisplay(), fontData); 324 } 325 bigTabFolder.setFont(m_bigTabFolderFont); 326 } 327 328 333 public void setBigButtonFont( 334 Button bigButton 335 ) 336 { 337 if (m_bigButtonFont == null) 338 { 339 Font initialFont = bigButton.getFont(); 340 FontData[] fontData = initialFont.getFontData(); 341 for (int i = 0; i < fontData.length; i++) 342 { 343 fontData[i].setHeight(BIG_BUTTON_FONT_HEIGHT); 344 } 345 m_bigButtonFont = new Font(bigButton.getDisplay(), fontData); 346 } 347 bigButton.setFont(m_bigButtonFont); 348 } 349 350 355 public void setBigTextFont( 356 Text bigText 357 ) 358 { 359 if (m_bigTextFont == null) 360 { 361 Font initialFont = bigText.getFont(); 362 FontData[] fontData = initialFont.getFontData(); 363 for (int i = 0; i < fontData.length; i++) 364 { 365 fontData[i].setHeight(BIG_TEXT_FONT_HEIGHT); 366 } 367 m_bigTextFont = new Font(bigText.getDisplay(), fontData); 368 } 369 bigText.setFont(m_bigTextFont); 370 } 371 372 377 public void setTableTextFont( 378 Text bigText 379 ) 380 { 381 if (m_bigTableFont == null) 382 { 383 Font initialFont = bigText.getFont(); 384 FontData[] fontData = initialFont.getFontData(); 385 for (int i = 0; i < fontData.length; i++) 386 { 387 fontData[i].setHeight(BIG_TABLE_FONT_HEIGHT); 388 } 389 m_bigTableFont = new Font(bigText.getDisplay(), fontData); 390 } 391 bigText.setFont(m_bigTableFont); 392 } 393 394 399 public void setBigComboTextFont( 400 Combo bigCombo 401 ) 402 { 403 if (m_bigComboFont == null) 404 { 405 Font initialFont = bigCombo.getFont(); 406 FontData[] fontData = initialFont.getFontData(); 407 for (int i = 0; i < fontData.length; i++) 408 { 409 fontData[i].setHeight(BIG_COMBO_FONT_HEIGHT); 410 } 411 m_bigComboFont = new Font(bigCombo.getDisplay(), fontData); 412 } 413 bigCombo.setFont(m_bigComboFont); 414 } 415 416 421 public void setBigListTextFont( 422 List bigList 423 ) 424 { 425 if (m_bigListFont == null) 426 { 427 Font initialFont = bigList.getFont(); 428 FontData[] fontData = initialFont.getFontData(); 429 for (int i = 0; i < fontData.length; i++) 430 { 431 fontData[i].setHeight(BIG_LIST_FONT_HEIGHT); 432 } 433 m_bigListFont = new Font(bigList.getDisplay(), fontData); 434 } 435 bigList.setFont(m_bigListFont); 436 } 437 438 443 public void setBigTableFont( 444 Table bigTable 445 ) 446 { 447 if (m_bigTableFont == null) 448 { 449 Font initialFont = bigTable.getFont(); 450 FontData[] fontData = initialFont.getFontData(); 451 for (int i = 0; i < fontData.length; i++) 452 { 453 fontData[i].setHeight(BIG_TABLE_FONT_HEIGHT); 454 } 455 m_bigTableFont = new Font(bigTable.getDisplay(), fontData); 456 } 457 bigTable.setFont(m_bigTableFont); 458 } 459 460 465 public void setMiddleLabelFont( 466 Label middleLabel 467 ) 468 { 469 if (m_middleLabelFont == null) 470 { 471 Font initialFont = middleLabel.getFont(); 472 FontData[] fontData = initialFont.getFontData(); 473 for (int i = 0; i < fontData.length; i++) 474 { 475 fontData[i].setHeight(MIDDLE_TEXT_FONT_HEIGHT); 476 } 477 m_middleLabelFont = new Font(middleLabel.getDisplay(), fontData); 478 } 479 middleLabel.setFont(m_middleLabelFont); 480 } 481 482 487 public void setBigLabelFont( 488 Label bigLabel 489 ) 490 { 491 if (m_bigLabelFont == null) 492 { 493 Font initialFont = bigLabel.getFont(); 494 FontData[] fontData = initialFont.getFontData(); 495 for (int i = 0; i < fontData.length; i++) 496 { 497 fontData[i].setHeight(BIG_TEXT_FONT_HEIGHT); 498 } 499 m_bigLabelFont = new Font(bigLabel.getDisplay(), fontData); 500 } 501 bigLabel.setFont(m_bigLabelFont); 502 } 503 504 509 public void setWaitCursor( 510 Control ctlControl 511 ) 512 { 513 if (m_waitCursor == null) 514 { 515 m_waitCursor = new Cursor(ctlControl.getDisplay(), SWT.CURSOR_WAIT); 516 } 517 ctlControl.setCursor(m_waitCursor); 518 } 519 520 525 public void setDefaultCursor( 526 Control ctlControl 527 ) 528 { 529 if (m_defaultCursor == null) 530 { 531 m_defaultCursor = new Cursor(ctlControl.getDisplay(), SWT.CURSOR_ARROW); 533 } 534 ctlControl.setCursor(m_defaultCursor); 535 } 536 537 542 public void setDefaultCursor( 543 Shell window 544 ) 545 { 546 if (m_defaultCursor == null) 547 { 548 m_defaultCursor = new Cursor(window.getDisplay(), SWT.CURSOR_ARROW); 550 } 551 window.setCursor(m_defaultCursor); 552 } 553 554 561 public void setHiddenDefaultCursor( 562 Display defaultDisplay 563 ) 564 { 565 if (m_blankImage == null) 566 { 567 if (m_defaultCursor != null) 568 { 569 m_defaultCursor.dispose(); 572 } 573 574 m_blankImage = new Image(defaultDisplay, 1, 1); 577 m_defaultCursor = new Cursor(defaultDisplay, m_blankImage.getImageData(), 578 0, 0); 579 } 580 } 581 } 582 | Popular Tags |