/*
Copyright 2006 Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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
");
TXT += "
";
}
newline = true;
} else {
newline = false;
if (s.startsWith(" ")) {
TXT += "
";
// T.append("
");
}
// T.append(s+" ");
TXT += s + " ";
}
} else if (pair != null && !s.startsWith(".")) {
pair[1] = s;
Other.addElement(pair);
lastpair = pair;
pair = null;
if (Search != null && (s.indexOf(Search) >= 0 || s.indexOf(Search1) >= 0)) {
if (!SearchResult.equals(lastpair[0])) {
SearchResults.addElement(lastpair);
SearchResult = lastpair[0];
if (!FoundHeader) {
FoundTopic = lastpair[0];
}
FoundHeader = true;
}
}
}
continue newline;
}
}
// T.append("
");
TXT += "
";
in.close();
} catch (final Exception e) {
if (!lang.equals("")) {
lang = "";
continue read;
} else {
// V.appendLine(
// Global.name("help.error","Could not find the help file!"));
// T.append(Global.name("help.error",
// "Could not find the help file!"));
TXT += Global.name("help.error", "Could not find the help file!");
}
}
if (FoundTopic != null && FirstRun) {
Subject = FoundTopic;
SearchResults = new Vector();
SearchResult = "";
pair = null;
lastpair = null;
Found = false;
TXT = "";
// T.setText("");
// V.setText("");
FirstRun = false;
continue read;
} else {
break read;
}
}
// if (!Found)
// V.appendLine(Global.name("info.notfound","Topic not found!"));
if (!Found) {
// T.append(Global.name("info.notfound", "Topic not found!"));
TXT += Global.name("info.notfound", "Topic not found!");
}
if (Search != null) {
if (SearchResults.size() > 0) {
TSearch.L.addI(Global.name("info.searchresults"));
} else {
TSearch.L.addI(Global.name("info.noresults"));
}
} else {
TSearch.L.addI(Global.name("info.select"));
}
if (Search == null && Related != null) {
final Enumeration e = Related.elements();
while (e.hasMoreElements()) {
final String topic = (String) e.nextElement();
final Enumeration ev = Other.elements();
while (ev.hasMoreElements()) {
final String s[] = (String[]) ev.nextElement();
if (s[0].equals(topic)) {
TSearch.L.addI(s[1]);
break;
}
}
}
}
if (Search != null) {
final Enumeration e = SearchResults.elements();
while (e.hasMoreElements()) {
final String s[] = (String[]) e.nextElement();
TSearch.L.addI(s[1]);
}
}
T.setContent(TXT);
if (WithTextFocus) {
focusTxt();
}
T.setCaretPosition(0);
History.addElement(Subject);
TSearch.setCount();
if (vis) {
TSearch.showpopup();
}
}
public String clear(String s) {
s = s.replace('ß', ' ');
s = s.replaceAll("__", "");
return s;
}
}
class MyComboBoxUI extends MetalComboBoxUI {
public static ComponentUI createUI(final JComponent c) {
return new MyComboBoxUI();
}
}
class MyJTextSearch extends JEricPanel {
private static final long serialVersionUID = 1L;
JLabel cntLBL = new JLabel();
JTextField JTF;
JHelpPanel JP;
JButton popBTN, clearBTN;
JEricPanel txtpanel;
JEricPanel wholepanel;
MyJPopupMenu L;
String old = "";
@Override
public void paintComponent(final java.awt.Graphics g) {
super.paintComponent(g);
final ImageIcon OffImage = new ImageIcon(getClass().getResource("/eric/GUI/icons/themes/common/helpsearchback.png"));
final java.awt.Dimension d = this.getSize();
g.drawImage(OffImage.getImage(), 0, 0, d.width, d.height, this);
}
public MyJTextSearch(final JHelpPanel jp) {
super();
setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
setOpaque(false);
JP = jp;
L = new MyJPopupMenu(JP);
txtpanel = new JEricPanel();
txtpanel.setLayout(new javax.swing.BoxLayout(txtpanel, javax.swing.BoxLayout.X_AXIS));
txtpanel.setBorder(BorderFactory.createLineBorder(new Color(150, 150, 150), 1));
txtpanel.setOpaque(true);
txtpanel.setBackground(Color.WHITE);
wholepanel = new JEricPanel();
wholepanel.setLayout(new javax.swing.BoxLayout(wholepanel, javax.swing.BoxLayout.X_AXIS));
wholepanel.setBorder(BorderFactory.createEmptyBorder());
wholepanel.setOpaque(false);
cntLBL.setOpaque(false);
cntLBL.setText("");
cntLBL.setFont(new Font("System", 0, 9));
cntLBL.setHorizontalAlignment(SwingConstants.CENTER);
cntLBL.setVerticalAlignment(SwingConstants.CENTER);
JHelpPanel.fixsize(cntLBL, 20, 18);
JTF = new JTextField();
JTF.setFont(new Font("System", 0, 11));
JTF.setForeground(new Color(50, 50, 50));
JTF.setBackground(new Color(255, 255, 255));
JTF.setBorder(BorderFactory.createEmptyBorder());
JTF.setMargin(new java.awt.Insets(0, 0, 1, 0));
JTF.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(final KeyEvent e) {
if (JTF.getText().equals("")) {
clearBTN.setVisible(false);
} else {
clearBTN.setVisible(true);
}
if ((e.getKeyCode() == KeyEvent.VK_ENTER) || (e.getKeyCode() == KeyEvent.VK_UP)) {
hidepopup();
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
showpopup();
} else {
doSearch(JTF.getText());
}
}
});
// JTF.setFocusable(true);
JTF.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
JTF.selectAll();
}
});
final ImageIcon carimg = new ImageIcon(getClass().getResource("/eric/GUI/icons/themes/common/helpsearch1.gif"));
popBTN = new JButton(carimg);
popBTN.setBorder(BorderFactory.createEmptyBorder());
popBTN.setOpaque(true);
popBTN.setContentAreaFilled(true);
popBTN.setFocusable(false);
popBTN.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
showpopup();
}
});
final ImageIcon carimg2 = new ImageIcon(getClass().getResource("/eric/GUI/icons/themes/common/helpsearch2.png"));
final JButton backBTN = new JButton(carimg2);
backBTN.setBorder(BorderFactory.createEmptyBorder());
backBTN.setOpaque(false);
backBTN.setContentAreaFilled(false);
backBTN.setFocusable(false);
backBTN.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
final int n = JP.History.size();
if (n < 2) {
return;
}
JP.History.removeElementAt(n - 1);
JHelpPanel.Subject = (String) JP.History.elementAt(n - 2);
JP.History.removeElementAt(n - 2);
JP.fill(true);
}
});
final ImageIcon carimg3 = new ImageIcon(getClass().getResource("/eric/GUI/icons/themes/common/helpsearch3.gif"));
clearBTN = new JButton(carimg3);
clearBTN.setBorder(BorderFactory.createEmptyBorder());
clearBTN.setOpaque(true);
clearBTN.setContentAreaFilled(true);
clearBTN.setFocusable(false);
clearBTN.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
JTF.setText("");
clearBTN.setVisible(false);
doSearch("");
}
});
clearBTN.setVisible(false);
JHelpPanel.fixsize(popBTN, carimg.getIconWidth(), carimg.getIconHeight());
JHelpPanel.fixsize(clearBTN, carimg3.getIconWidth(), carimg3.getIconHeight());
txtpanel.add(cntLBL);
txtpanel.add(popBTN);
txtpanel.add(JHelpPanel.margin(3));
txtpanel.add(JTF);
txtpanel.add(clearBTN);
wholepanel.add(JHelpPanel.margin(5));
wholepanel.add(txtpanel);
wholepanel.add(JHelpPanel.margin(3));
wholepanel.add(backBTN);
this.add(JHelpPanel.vmargin(3));
this.add(wholepanel);
}
void showpopup() {
if (L.Count > 1) {
L.show(popBTN, 10, 20);
}
}
void hidepopup() {
L.setVisible(false);
}
boolean ispopupvisible() {
return L.isVisible();
}
void doSearch(final String s) {
if (s.equals("")) {
JP.Search = null;
} else {
JP.Search = s;
}
JHelpPanel.Subject = "start";
JP.fill(true);
JP.Search = null;
}
void setCount() {
if (L.Count > 1) {
cntLBL.setText("(" + (L.Count - 1) + ")");
} else {
cntLBL.setText("");
}
}
}
class MyJPopupMenuItem extends JMenuItem {
private static final long serialVersionUID = 1L;
String STR;
JHelpPanel JP;
public MyJPopupMenuItem(final JHelpPanel jp, final String s) {
super(s.replaceAll("
", "").replace("
", ", "));
STR = s;
JP = jp;
setFont(new Font("System", 0, 11));
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent arg0) {
JP.TSearch.L.setVisible(false);
JP.TSearch.JTF.setText("");
JP.TSearch.clearBTN.setVisible(false);
final String s = STR;
final Enumeration ev = JP.Other.elements();
while (ev.hasMoreElements()) {
final String p[] = (String[]) ev.nextElement();
if (p[1].equals(s)) {
JHelpPanel.Subject = p[0];
JP.fill(true);
break;
}
}
}
});
}
}
class MyJPopupMenu extends JPopupMenu {
private static final long serialVersionUID = 1L;
int Count = 0;
JHelpPanel JP;
public MyJPopupMenu(final JHelpPanel jp) {
super();
JP = jp;
setFont(new Font("System", 0, 11));
setFocusable(false);
}
public void addI(final String s) {
Count++;
add(new MyJPopupMenuItem(JP, s));
}
}
class MyJTextPane extends JEditorPane implements HyperlinkListener {
private static final long serialVersionUID = 1L;
String content;
HTMLEditorKit editorkit;
HTMLDocument doc;
JHelpPanel JP;
public MyJTextPane(final JHelpPanel jp) {
super();
JP = jp;
this.setContentType("text/html;");
editorkit = (HTMLEditorKit) getEditorKit();
doc = (HTMLDocument) getDocument();
final StyleSheet myStyleSheet = new StyleSheet();
myStyleSheet.addRule("body {color: #333333;font-family: Verdana, Arial, Helvetica, sans-serif;"
+ "text-align: justify;font-size: 10px;background-color: #F1F3F9;}");
myStyleSheet.addRule("ul {text-align: left;list-style-type: disc;padding-left: 15px;list-style-position: outside;}");
myStyleSheet.addRule(".pfooter {text-align: center;font-size: 10px;padding-bottom: 5px;"
+ "padding-top: 5px;background-color: #eaedf3;}");
myStyleSheet.addRule(".pfootertitle {font-weight: bold;text-align: center;font-size: 10px;padding-bottom: 5px;"
+ "padding-top: 5px;background-color: #DBDDE3;}");
myStyleSheet.addRule("a {color: #0a9100;text-decoration: none;}");
myStyleSheet.addRule(".aanchor {color: #CC6633;}");
myStyleSheet.addRule(".centered {text-align: center;}");
myStyleSheet.addRule(".comment {text-align: center;font-size: 9px;font-style: oblique;font-weight: normal;}");
myStyleSheet.addRule(".comment2 {text-align: justify;font-size: 9px;font-style: oblique;font-weight: normal;}");
myStyleSheet.addRule(".ttle {color: #000000;font-family: Verdana, Arial, Helvetica, sans-serif;"
+ "text-align: center;font-weight: bold;font-size: 11px;background-color: #DBDDE3;}");
myStyleSheet.addRule(".tab {border-width: 1px;border-color: #909090;border-style:solid;}");
myStyleSheet.addRule(".tds {border-width: 1px;border-color: #909090;border-style:solid;background-color: #DBDDE3;}");
myStyleSheet.addRule(".image {border-width: 1px;border-color: #909090;border-style:solid;background-color: #F1F3F9;}");
editorkit.setStyleSheet(myStyleSheet);
this.setEditable(false);
addHyperlinkListener(this);
}
void fixImagePath() {
final String SP = System.getProperty("file.separator");
// Check if there are external images (inside the docs folder of
// carmetal_config directory
Pattern p = Pattern.compile("(]*src=\")(images/)([^\"]+)(\"[^>]*>)", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(content);
StringBuffer sb = new StringBuffer();
while (m.find()) {
String myst = "
" + m.group(1) + "file:///"; myst += Global.getHomeDirectory().replace("\\", "\\\\"); myst += "docs/images/".replace("/", SP).replace("\\", "\\\\"); myst += m.group(3).replace("/", SP).replace("\\", "\\\\"); // on windows, the img tag seems to need the width and height // attribute : final ImageIcon myimg = new ImageIcon(Global.getHomeDirectory() + "docs/images/" + m.group(3)); if (myimg != null) { myst += "\" width=\"" + myimg.getIconWidth() + "\" height=\"" + myimg.getIconHeight() + "\""; } myst += m.group(4); myst += "
"; m.appendReplacement(sb, myst); } m.appendTail(sb); m.reset(); content = sb.toString(); // Check if there are internal images (inside the jar archive with root // eric/GUI/icons/ : p = Pattern.compile("(]*src=\")(#)([^\"]+)(\"[^>]*>)", Pattern.CASE_INSENSITIVE); m = p.matcher(content); sb = new StringBuffer(); while (m.find()) { final URL myIMG = Global.getPath("eric/GUI/icons/" + m.group(3)); if (myIMG == null) continue; String myst = m.group(1); myst += myIMG.toString(); myst += m.group(4); m.appendReplacement(sb, myst); } m.appendTail(sb); m.reset(); content = sb.toString(); } void setTitle() { if (content.equals("")) { return; } content = content.replace("href=\"#", "class=\"aanchor\" href=\"#"); final URL myIMG = Global.getPath("eric/GUI/icons/palette/" + JHelpPanel.Subject + ".png"); final String mytitle = content.substring(0, content.indexOf("" + mytitle + " | "; tag += "
" + mytitle + " | "; tag += ""; tag += " |
" + Global.Loc("contexthelp.seealso") + " |