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.Version; 040 import sears.gui.resources.SearsResources; 041 import sears.tools.SearsResourceBundle; 042 import sears.tools.Trace; 043 044 /** 045 * Class JDialogAbout. 046 * <br><b>Summary:</b><br> 047 * Allows to display the about window. 048 */ 049 public class JDialogAbout extends SearsJDialog { 050 private static final long serialVersionUID = 5648489779666362013L; 051 052 /**The application icon*/ 053 private ImageIcon searsIcon; 054 055 private JPanel jAboutPanel = null; 056 057 private JLabel iconField = null; 058 059 private JLabel titleLabel = null; 060 061 private JEditorPane aboutRTFViewer = null; 062 063 /** 064 * Constructor JDialogAbout. 065 * <br><b>Summary:</b><br> 066 * Constructor of the class. 067 * @param title the title for this dialog 068 */ 069 public JDialogAbout(String title) { 070 super(SearsResourceBundle.getResource("about_title")); 071 // we initialize the sears icon: 072 searsIcon = SearsResources.getIcon("SearsGUIIcon"); 073 initialize(); 074 075 } 076 077 /** 078 * This method initializes this 079 */ 080 private void initialize(){ 081 setResizable(false); 082 // we add about panel to the content pane: 083 setContentPane(getJAboutPanel()); 084 // we add components to the about panel: 085 jAboutPanel.add(getIconLabel(), BorderLayout.NORTH); 086 jAboutPanel.add(getTitleLabel(), BorderLayout.CENTER); 087 jAboutPanel.add(getAboutRTFViewer(), BorderLayout.SOUTH); 088 } 089 090 /** 091 * this method initializes the about label. 092 * @return a JLabel 093 */ 094 private JPanel getJAboutPanel(){ 095 if(jAboutPanel == null){ 096 //we initialize the about panel: 097 jAboutPanel = new JPanel(new BorderLayout(3,10)); 098 // we create border: 099 jAboutPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 100 } 101 return jAboutPanel; 102 } 103 104 /** 105 * this method initializes the icon label. 106 * @return a JLabel 107 */ 108 private JLabel getIconLabel(){ 109 if(iconField == null){ 110 iconField = new JLabel(searsIcon); 111 } 112 return iconField; 113 } 114 115 /** 116 * this method initializes the rft viewer. 117 * @return a JEditorPane, an RTF Viewer 118 */ 119 120 private JEditorPane getAboutRTFViewer(){ 121 // text area for display information about developpers...etc 122 // Create an RTF viewer (non editable) window, aboutRTFViewer: 123 if(aboutRTFViewer == null){ 124 // we create a RTF editor an transform it to a simple viewer: 125 RTFEditorKit rtf = new RTFEditorKit(); 126 aboutRTFViewer = new JEditorPane(); 127 aboutRTFViewer.setEditorKit(rtf); 128 aboutRTFViewer.setBackground(Color.white); 129 aboutRTFViewer.setEditable(false); 130 aboutRTFViewer.setDragEnabled(false); 131 aboutRTFViewer.setFocusable(true); 132 aboutRTFViewer.setMargin(new Insets(3,5,3,5)); 133 aboutRTFViewer.setMaximumSize(new Dimension(10,10)); 134 aboutRTFViewer.setMinimumSize(new Dimension(10,10)); 135 136 //we get back the rtf file path: 137 URL aboutSearsRTFFile = MainWindow.instance.getClass().getResource("/sears/gui/resources/searsAbout.rtf"); 138 139 try { 140 InputStream fi = aboutSearsRTFFile.openStream(); 141 rtf.read( fi, aboutRTFViewer.getDocument(), 0 ); 142 } catch( FileNotFoundException e ){ 143 Trace.warning("Can't find resource: " + aboutSearsRTFFile ); 144 //set text to none 145 aboutRTFViewer.setText(""); 146 } catch (IOException e) { 147 // read acces error: 148 Trace.warning("Can't open or read: " + aboutSearsRTFFile.getFile()); 149 // set text to none 150 aboutRTFViewer.setText(""); 151 } catch (BadLocationException e) { 152 // set text to none 153 aboutRTFViewer.setText(""); 154 } 155 } 156 157 return aboutRTFViewer; 158 } 159 160 161 /** 162 * this method return the title label. 163 * @return a JLabel 164 */ 165 private JLabel getTitleLabel(){ 166 //title label: Sears name and version: 167 if(titleLabel == null){ 168 titleLabel = new JLabel("Sears " + Version.VERSION, JLabel.CENTER); 169 titleLabel.setFont(new Font("Lucida", Font.PLAIN, 14)); 170 } 171 172 return titleLabel; 173 } 174 175 176 public void windowClosed(WindowEvent e) { 177 // don't save preference size 178 } 179 180 /* (non-Javadoc) 181 * @see sears.gui.SearsJDialog#getDialogName() 182 */ 183 protected String getDialogName() { 184 return "about"; 185 } 186 187 }