/*
* Copyright (C) 2014 Vinu K.N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.domainmath.gui.pkgview;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.print.PrinterException;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import org.domainmath.gui.MainFrame;
import org.domainmath.gui.help.QuickHelpPanel;
import org.domainmath.gui.pkgview.doc.IndexPanel;
import org.domainmath.gui.pkgview.doc.PkgTreePanel;
import org.flexdock.docking.DockingConstants;
import org.flexdock.view.View;
import org.flexdock.view.Viewport;
import org.flexdock.view.actions.DefaultDisplayAction;
/**
*
* @author Vinu K.N
*/
public class PkgDocFrame extends javax.swing.JFrame implements DockingConstants {
private final PkgTreePanel pkgTreePanel;
private final QuickHelpPanel quickHelpPanel;
private final IndexPanel indexPanel;
private final File pkgFile;
/**
* Creates new form PkgDocFrame
*/
public PkgDocFrame(MainFrame frame) {
this.setIconImage(icon);
initComponents();
setSize(800, 600);
quickHelpPanel = new QuickHelpPanel();
pkgFile=new File(System.getProperty("user.dir")
+File.separator+"cache"+File.separator+"pkg_list.xml");
pkgTreePanel = new PkgTreePanel(frame,quickHelpPanel,pkgFile);
indexPanel = new IndexPanel(frame,quickHelpPanel,pkgFile);
add(createContentPane(),BorderLayout.CENTER);
pack();
this.pinButton.setText("");
}
private JPanel createContentPane() {
JPanel p = new JPanel(new BorderLayout(0, 0));
p.setBorder(new EmptyBorder(5, 5, 5, 5));
Viewport viewport = new Viewport();
p.add(viewport, BorderLayout.CENTER);
View startPage = createStartPage();
JTabbedPane pane = new JTabbedPane();
pane.addTab("Contents", pkgTreePanel);
pane.addTab("Index", indexPanel);
View view1 = createView("Help Contents", "Help Contents",pane);
viewport.dock(startPage);
startPage.dock(view1, WEST_REGION, .3f);
return p;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
statusPanel1 = new org.domainmath.gui.StatusPanel();
jToolBar1 = new javax.swing.JToolBar();
pinButton = new javax.swing.JButton();
printButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Package Documentation");
setMinimumSize(new java.awt.Dimension(800, 600));
getContentPane().add(statusPanel1, java.awt.BorderLayout.PAGE_END);
jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);
pinButton.setAction(new DefaultDisplayAction("Help Contents"));
pinButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/domainmath/gui/pkgview/resources/application-side-expand.png"))); // NOI18N
pinButton.setToolTipText("");
pinButton.setFocusable(false);
pinButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
pinButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToolBar1.add(pinButton);
printButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/domainmath/gui/pkgview/resources/document-print-5.png"))); // NOI18N
printButton.setToolTipText("Print");
printButton.setFocusable(false);
printButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
printButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
printButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
printButtonActionPerformed(evt);
}
});
jToolBar1.add(printButton);
getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);
pack();
}// </editor-fold>//GEN-END:initComponents
private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButtonActionPerformed
try {
this.quickHelpPanel.getHtmlView().print();
} catch (PrinterException ex) {
Logger.getLogger(PkgDocFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_printButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(PkgDocFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PkgDocFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PkgDocFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PkgDocFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PkgDocFrame(null).setVisible(true);
}
});
}
public Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/org/domainmath/gui/resources/DomainMath.png"));
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JToolBar jToolBar1;
private javax.swing.JButton pinButton;
private javax.swing.JButton printButton;
private org.domainmath.gui.StatusPanel statusPanel1;
// End of variables declaration//GEN-END:variables
private View createView(String id, String text,JTabbedPane p) {
View view = new View(id, text);
view.addAction(CLOSE_ACTION);
view.addAction(PIN_ACTION);
p.setBorder(new LineBorder(Color.GRAY, 1));
view.setContentPane(p);
return view;
}
private View createStartPage() {
String id = "QuickHelp";
View view = new View(id, null, null);
view.setTerritoryBlocked(CENTER_REGION, true);
view.setTitlebar(null);
view.setContentPane(quickHelpPanel);
return view;
}
}