001 ///////////////////////////////////////////////// 002 // This file is part of Sears project. 003 // Subtitle Editor And Re-Synch 004 // A tool to easily modify and resynch movies subtitles. 005 ///////////////////////////////////////////////// 006 //This program is free software; 007 //you can redistribute it and/or modify it under the terms 008 //of the GNU General Public License 009 //as published by the Free Software Foundation; 010 //either version 2 of the License, or (at your option) any later version. 011 ///////////////////////////////////////////////// 012 //Sears project is available under sourceforge 013 // at adress: http://sourceforge.net/projects/sears/ 014 //Copyright (C) 2005 Booba Skaya 015 //Mail: booba.skaya@gmail.com 016 //////////////////////////////////////////////// 017 018 package sears.gui; 019 020 import java.awt.BorderLayout; 021 import java.awt.Color; 022 import java.awt.Dimension; 023 import java.awt.Font; 024 import java.awt.Insets; 025 import java.awt.event.WindowEvent; 026 import java.io.FileNotFoundException; 027 import java.io.IOException; 028 import java.io.InputStream; 029 import java.net.URL; 030 031 import javax.swing.BorderFactory; 032 import javax.swing.ImageIcon; 033 import javax.swing.JEditorPane; 034 import javax.swing.JLabel; 035 import javax.swing.JPanel; 036 import javax.swing.text.BadLocationException; 037 import javax.swing.text.rtf.RTFEditorKit; 038 039 import sears.gui.resources.SearsResources; 040 import sears.tools.SearsResourceBundle; 041 import sears.tools.Trace; 042 043 /** 044 * Class JDialogAbout. 045 * <br><b>Summary:</b><br> 046 * Allows to display the about window. 047 */ 048 public class JDialogAbout extends SearsJDialog { 049 private static final long serialVersionUID = 5648489779666362013L; 050 051 /**The application icon*/ 052 private ImageIcon searsIcon; 053 054 private JPanel jAboutPanel = null; 055 056 private JLabel iconField = null; 057 058 private JLabel titleLabel = null; 059 060 private JEditorPane aboutRTFViewer = null; 061 062 /** 063 * Constructor JDialogAbout. 064 * <br><b>Summary:</b><br> 065 * Constructor of the class. 066 */ 067 public JDialogAbout(String title) { 068 super(SearsResourceBundle.getResource("about_title")); 069 // we initialize the sears icon: 070 searsIcon = SearsResources.getIcon("SearsGUIIcon"); 071 initialize(); 072 073 } 074 075 /** 076 * This method initializes this 077 * @return void 078 */ 079 private void initialize(){ 080 setResizable(false); 081 // we add about panel to the content pane: 082 setContentPane(getJAboutPanel()); 083 // we add components to the about panel: 084 jAboutPanel.add(getIconLabel(), BorderLayout.NORTH); 085 jAboutPanel.add(getTitleLabel(), BorderLayout.CENTER); 086 jAboutPanel.add(getAboutRTFViewer(), BorderLayout.SOUTH); 087 } 088 089 /** 090 * this method initializes the about label. 091 * @return a JLabel 092 */ 093 private JPanel getJAboutPanel(){ 094 if(jAboutPanel == null){ 095 //we initialize the about panel: 096 jAboutPanel = new JPanel(new BorderLayout(3,10)); 097 // we create border: 098 jAboutPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 099 } 100 return jAboutPanel; 101 } 102 103 /** 104 * this method initializes the icon label. 105 * @return a JLabel 106 */ 107 private JLabel getIconLabel(){ 108 if(iconField == null){ 109 iconField = new JLabel(searsIcon); 110 } 111 return iconField; 112 } 113 114 /** 115 * this method initializes the rft viewer. 116 * @return a JEditorPane, an RTF Viewer 117 */ 118 119 private JEditorPane getAboutRTFViewer(){ 120 // text area for display information about developpers...etc 121 // Create an RTF viewer (non editable) window, aboutRTFViewer: 122 if(aboutRTFViewer == null){ 123 // we create a RTF editor an transform it to a simple viewer: 124 RTFEditorKit rtf = new RTFEditorKit(); 125 aboutRTFViewer = new JEditorPane(); 126 aboutRTFViewer.setEditorKit(rtf); 127 aboutRTFViewer.setBackground(Color.white); 128 aboutRTFViewer.setEditable(false); 129 aboutRTFViewer.setDragEnabled(false); 130 aboutRTFViewer.setFocusable(true); 131 aboutRTFViewer.setMargin(new Insets(3,5,3,5)); 132 aboutRTFViewer.setMaximumSize(new Dimension(10,10)); 133 aboutRTFViewer.setMinimumSize(new Dimension(10,10)); 134 135 //we get back the rtf file path: 136 URL aboutSearsRTFFile = MainWindow.instance.getClass().getResource("/sears/gui/resources/searsAbout.rtf"); 137 138 try { 139 InputStream fi = aboutSearsRTFFile.openStream(); 140 rtf.read( fi, aboutRTFViewer.getDocument(), 0 ); 141 } catch( FileNotFoundException e ){ 142 Trace.warning("Can't find resource: " + aboutSearsRTFFile ); 143 //set text to none 144 aboutRTFViewer.setText(""); 145 } catch (IOException e) { 146 // read acces error: 147 Trace.warning("Can't open or read: " + aboutSearsRTFFile.getFile()); 148 // set text to none 149 aboutRTFViewer.setText(""); 150 } catch (BadLocationException e) { 151 // set text to none 152 aboutRTFViewer.setText(""); 153 } 154 } 155 156 return aboutRTFViewer; 157 } 158 159 160 /** 161 * this method return the title label. 162 * @return a JLabel 163 */ 164 private JLabel getTitleLabel(){ 165 //title label: Sears name and version: 166 if(titleLabel == null){ 167 titleLabel = new JLabel("Sears" + SearsResources.getString("SearsVersion"), JLabel.CENTER); 168 titleLabel.setFont(new Font("Lucida", Font.PLAIN, 14)); 169 } 170 171 return titleLabel; 172 } 173 174 175 public void windowClosed(WindowEvent e) { 176 // don't save preference size 177 } 178 179 /* (non-Javadoc) 180 * @see sears.gui.SearsJDialog#getDialogName() 181 */ 182 protected String getDialogName() { 183 return "about"; 184 } 185 186 }