1 /* 2 * @(#)ApiDemo.java 1.81 06/10/30 3 * 4 * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * - Redistribution of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * - Redistribution in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * Neither the name of Sun Microsystems, Inc. or the names of 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * This software is provided "AS IS," without a warranty of any 23 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 24 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 25 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY 26 * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 27 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 28 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS 29 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 30 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, 31 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND 32 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR 33 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGES. 35 * 36 * You acknowledge that this software is not designed, licensed or 37 * intended for use in the design, construction, operation or 38 * maintenance of any nuclear facility. 39 */ 40 41 package sunw.demo.idedemo; 42 43 import java.util.*; 44 import java.net.URL; 45 import java.awt.*; 46 import java.awt.event.*; 47 import java.applet.*; 48 import java.lang.reflect.*; 49 import javax.help.*; 50 import javax.swing.*; 51 import javax.swing.text.*; 52 import sunw.demo.classviewer.ClassViewerNavigator; 53 import java.beans.PropertyVetoException; 54 import javax.help.Map.ID; 55 56 /** 57 * This class is the main class of the IdeHelp demo 58 * 59 * @author Roger D. Brinkley 60 * @author Eduardo Pelegri-Llopart 61 * @version 1.81 10/30/06 62 */ 63 64 public class ApiDemo extends JPanel implements ActionListener { 65 66 private static boolean hasCustomCursor; 67 68 static String swingPkg = "javax.swing.plaf."; 69 //static String swingPkg = "com.sun.java.swing.plaf."; 70 static JFrame frame; 71 72 // Defaults for Main Help 73 static final String helpsetName = "IdeHelp"; 74 static final String helpsetLabel = "Demo JDE - Help"; 75 76 // Main HelpSet & Broker 77 HelpSet mainHS = null; 78 HelpBroker mainHB; 79 80 // The JavaDoc Help 81 HelpSet apiHS = null; 82 HelpBroker apiHB; 83 84 85 // Auxiliaries 86 JRootPane rootpane; 87 JSplitPane split; 88 JMenuItem menuItem, menu_help, menu_open, menu_apihelp; 89 JTabbedPane messages; 90 int miscTabIndex; 91 92 // Workaround for 1.1.4 compiler bug 93 JMenuItem item1, item2; 94 95 // The initial width and height of the frame 96 public static int WIDTH = 845; 97 public static int HEIGHT = 495; 98 99 public static int JH_WIDTH = 645; 100 public static int JH_HEIGHT = 495; 101 102 // The internal desktop 103 JDesktopPane desktop; 104 105 // For the Source JInternalFrame 106 JInternalFrame sourceIFrame; 107 108 // For the ClassViewer JInternalFrame 109 JInternalFrame classViewerIFrame; 110 111 JButton helpbutton; 112 private final boolean showTimes = false; // should be using a timer -epll 113 ApiDemo()114 ApiDemo() { 115 116 // Create the main HelpBroker, then the api HelpBroker 117 // (these could be done on-demand, but they are quite fast for our 118 // case; this might be different if the HelpSet was non-local). 119 120 if (showTimes) 121 System.err.print("creating mainHB..."); 122 123 try { 124 ClassLoader cl = ApiDemo.class.getClassLoader(); 125 URL url = HelpSet.findHelpSet(cl, helpsetName); 126 mainHS = new HelpSet(cl, url); 127 } catch (Exception ee) { 128 System.out.println ("Help Set "+helpsetName+" not found"); 129 return; 130 } catch (ExceptionInInitializerError ex) { 131 System.err.println("initialization error:"); 132 ex.getException().printStackTrace(); 133 } 134 mainHB = mainHS.createHelpBroker(); 135 136 if (showTimes) 137 System.err.println(" done!"); 138 139 // The api HelpBroker. 140 141 if (showTimes) 142 System.err.print("creating apiHB..."); 143 144 try { 145 ClassLoader cl = ApiDemo.class.getClassLoader(); 146 URL url = HelpSet.findHelpSet(cl, "api"); 147 apiHS = new HelpSet(cl, url); 148 } catch (Exception ee) { 149 System.out.println ("API Help Set not found"); 150 return; 151 } 152 apiHB = apiHS.createHelpBroker("api"); // Use the Help Broker 153 154 if (showTimes) 155 System.err.println(" done!"); 156 157 // locate resource bundle 158 159 resources = ResourceBundle.getBundle("sunw.demo.idedemo.IdeDemo"); 160 if (resources == null) { 161 System.err.println("Resources for application IdeDemo not found"); 162 } 163 164 WindowListener l = new WindowAdapter() { 165 public void windowClosing(WindowEvent e) { 166 setVisible(false); 167 System.exit(0); 168 } 169 public void windowClosed(WindowEvent e) { 170 setVisible(false); 171 System.exit(0); 172 } 173 public void windowOpened(WindowEvent e) { 174 split.setDividerLocation(0.80); 175 // split.setDividerLocation(250); 176 } 177 }; 178 frame.addWindowListener(l); 179 rootpane = frame.getRootPane(); 180 // mainHB.enableHelpKey(rootpane, "top", null); 181 mainHB.enableHelpKey(rootpane, "top", mainHS, "javax.help.SecondaryWindow", null); 182 // mainHB.enableHelpKey(rootpane, "top", mainHS, "javax.help.Popup", null); 183 setLayout(new BorderLayout()); 184 185 JPanel header=new JPanel(); 186 header.setLayout(new BorderLayout()); 187 header.add(createMenus(),"North"); 188 header.add(createToolbar(),"South"); 189 190 add(header,"North"); 191 192 desktop = new JDesktopPane(); 193 desktop.setOpaque(true); 194 desktop.setDoubleBuffered(true); 195 196 createSourceIFrame(); 197 desktop.add(sourceIFrame, JLayeredPane.PALETTE_LAYER); 198 sourceIFrame.show(); 199 200 201 JPanel panel=new JPanel(); 202 panel.setLayout(new BorderLayout()); 203 messages=new JTabbedPane(); 204 205 JTextArea newtext=new JTextArea(); 206 newtext.setBackground(Color.white); 207 CSH.setHelpIDString(newtext, "build.build"); 208 messages.addTab("Build", newtext); 209 newtext = new JTextArea(); 210 CSH.setHelpIDString(newtext, "debug.overview"); 211 messages.addTab("Debug", newtext); 212 newtext = new JTextArea(); 213 CSH.setHelpIDString(newtext, "browse.strings"); 214 messages.addTab("String Search", newtext); 215 miscTabIndex = messages.getTabCount(); 216 messages.insertTab("Misc", null, new JTextArea(), null, miscTabIndex); 217 218 // Find out when we are selected. When doing so... 219 220 messages.setSelectedIndex(0); 221 messages.setDoubleBuffered(true); 222 panel.add(messages,"Center"); 223 split=new JSplitPane(JSplitPane.VERTICAL_SPLIT,desktop,panel); 224 //split.setDoubleBuffered(true); 225 split.setOneTouchExpandable(true); 226 227 add(split,"Center"); 228 229 } 230 231 /** 232 * Create a JButton out of a resource name 233 */ createButton(String name)234 private JButton createButton(String name) { 235 java.net.URL url = this.getClass().getResource(name); 236 ImageIcon icon = new ImageIcon(url); 237 return new JButton(icon); 238 } 239 createClassViewer()240 private void createClassViewer() { 241 if (classViewerIFrame != null) { 242 return; 243 } 244 classViewerIFrame = new JInternalFrame("Classes", true, true, true, true); 245 JComponent content = new JPanel(); 246 content.setLayout(new BorderLayout()); 247 content.setDoubleBuffered(true); 248 classViewerIFrame.setDoubleBuffered(true); 249 classViewerIFrame.setBounds(570,10,200,310); 250 251 JHelpNavigator xnav; 252 try { 253 // The content viewer 254 JHelpContentViewer viewer1 = new JHelpContentViewer(apiHS); 255 256 // Stuff it in the misc index of the Tab pane. 257 messages.setComponentAt(miscTabIndex, viewer1); 258 messages.setSelectedIndex(miscTabIndex); 259 260 // Create a ClassViewerNavigator sharing the same model 261 xnav = (JHelpNavigator) apiHS.getNavigatorView("TOC").createNavigator(viewer1.getModel()); 262 263 // Add the viewer to the presentation 264 content.add(xnav, "Center"); 265 classViewerIFrame.setContentPane(content); 266 267 } catch (Exception ee) { 268 System.err.println("Caught excpetion while creating ClassViewer: "+ee); 269 ee.printStackTrace(); 270 JTextArea sourceText = new JTextArea("Trouble adding Navigator"); 271 content.add(sourceText, "Center"); 272 } 273 } 274 275 createSourceIFrame()276 private void createSourceIFrame() { 277 if (sourceIFrame != null) { 278 return; 279 } 280 281 sourceIFrame = new JInternalFrame("Source", true, true, true, true); 282 CSH.setHelpIDString(sourceIFrame, "edit.editsource"); 283 JComponent c = (JComponent) sourceIFrame.getContentPane(); 284 c.setLayout(new BorderLayout()); 285 c.setDoubleBuffered(true); 286 sourceIFrame.setDoubleBuffered(true); 287 sourceIFrame.setBounds(10,10,550,310); 288 289 JTextArea sourceText = new JTextArea(""); 290 sourceText.setFont(new Font("Courier",Font.PLAIN,12)); 291 sourceText.setBackground(Color.white); 292 293 sourceText.append("/* To view JavaHelp click, Help, Java API Help */"+ 294 "\n\nimport java.applet.Applet;"+ 295 "\nimport java.awt.Graphics;"+ 296 "\n\npublic class HelloWorld extends Applet {"+ 297 "\n\n public void paint(Graphics g) {"+ 298 "\n g.drawString(\"Hello world!\", 50, 25);"+ 299 "\n }\n}\n"); 300 301 c.add(sourceText,"Center"); 302 } 303 304 ResourceBundle resources; 305 addButton(JToolBar toolbar, String img, String tipKey)306 private JButton addButton(JToolBar toolbar, String img, String tipKey) { 307 JButton button = createButton(img); 308 if (tipKey != null) { 309 try { 310 String tipText = 311 resources.getString("toolbar."+tipKey+".tip"); 312 button.setToolTipText(tipText); 313 } catch (Exception ex) { 314 System.err.println("Could not find a resource for "+tipKey); 315 } 316 } 317 toolbar.add(button); 318 return button; 319 } 320 createToolbar()321 public JToolBar createToolbar() { 322 JToolBar toolbar=new JToolBar(); 323 CSH.setHelpIDString(toolbar,"toolbar.main"); 324 325 326 addButton(toolbar, "images/open.gif", "open"); 327 addButton(toolbar, "images/save.gif", "save"); 328 toolbar.addSeparator(); 329 addButton(toolbar, "images/start.gif", "start"); 330 addButton(toolbar, "images/break.gif", "stop"); 331 addButton(toolbar, "images/setbreak.gif", "setbreak"); 332 addButton(toolbar, "images/resume.gif", "resume"); 333 addButton(toolbar, "images/goto.gif", "goto"); 334 addButton(toolbar, "images/goend.gif", "goend"); 335 addButton(toolbar, "images/skip.gif", "skip"); 336 toolbar.addSeparator(); 337 addButton(toolbar, "images/down.gif", "down"); 338 addButton(toolbar, "images/up.gif", "up"); 339 toolbar.addSeparator(); 340 helpbutton= addButton(toolbar, "images/help.gif", "help"); 341 helpbutton.addActionListener(new CSH.DisplayHelpAfterTracking(mainHB)); 342 helpbutton.setEnabled(hasCustomCursor); // enable only on 1.2 343 344 return toolbar; 345 } 346 addMenuItem(JMenu menu, String label, String tipKey)347 private JMenuItem addMenuItem(JMenu menu, String label, String tipKey) { 348 JMenuItem item = new JMenuItem(label); 349 if (tipKey != null) { 350 try { 351 String tipText = resources.getString("menu."+tipKey+".tip"); 352 item.setToolTipText(tipText); 353 } catch (Exception ex) { 354 System.err.println("Could not find a resource for "+tipKey); 355 } 356 } 357 menu.add(item); 358 return item; 359 } 360 361 // An Option Dialog. Not really good for help 362 showDialog1()363 private void showDialog1() { 364 Object options[] = {"OK", "CANCEL", "HELP"}; 365 int index = 366 JOptionPane.showOptionDialog(null, // parent 367 "Exit?", // message object 368 "Quit", // string title 369 JOptionPane.DEFAULT_OPTION, 370 JOptionPane.QUESTION_MESSAGE, 371 null, // Icon 372 options, 373 options[0] 374 ); 375 switch (index) { 376 case 0: 377 System.exit(0); 378 case 1: 379 break; 380 case 2: 381 System.err.println("will ask for help"); 382 break; 383 } 384 } 385 createMenus()386 public JMenuBar createMenus() { 387 JMenuBar menuBar = new JMenuBar(); 388 menuBar.setBackground(getBackground()); 389 // menuBar.setOpaque(true); 390 JMenu menu = new JMenu("File"); 391 CSH.setHelpIDString(menu, "menus.file"); 392 menu.setToolTipText("File operations"); 393 menuBar.add(menu); 394 addMenuItem(menu, "New", "file.new"); 395 addMenuItem(menu, "Open...", "file.open"); 396 menu.addSeparator(); 397 addMenuItem(menu, "Save", "file.save"); 398 addMenuItem(menu, "Save As...", "file.saveas"); 399 menu.addSeparator(); 400 menuItem = addMenuItem(menu, "Exit", "file.exit"); 401 402 // Ask for confirmation on exit 403 menuItem.addActionListener(new ActionListener() { 404 public void actionPerformed(ActionEvent e){ 405 406 Object options[] = {"OK", "CANCEL", "HELP"}; 407 int index = 408 JOptionPane.showOptionDialog(null, // parent 409 "Exit IdeDemo?", // message object 410 "Exit Confirmation", // string title 411 JOptionPane.DEFAULT_OPTION, 412 JOptionPane.QUESTION_MESSAGE, 413 null, // Icon 414 options, 415 options[0] 416 ); 417 switch (index) { 418 case 0: 419 System.exit(0); 420 case 1: 421 break; 422 case 2: 423 try { 424 mainHB.setCurrentID("menus.file"); 425 } catch (Exception be) { 426 } 427 break; 428 } 429 } 430 }); 431 432 menu = new JMenu("Edit"); 433 CSH.setHelpIDString(menu, "menus.edit"); 434 menuBar.add(menu); 435 addMenuItem(menu, "Undo", null); 436 addMenuItem(menu, "Redo", null); 437 addMenuItem(menu, "Cut", null); 438 addMenuItem(menu, "Copy", null); 439 addMenuItem(menu, "Paste", null); 440 menu.addSeparator(); 441 442 menuItem = addMenuItem(menu, "Find", null); 443 menuItem.addActionListener(new ActionListener() { 444 public void actionPerformed(ActionEvent e){ 445 JDialog dialog = new FindDialog(ApiDemo.this, null); // non-modal 446 dialog.show(); 447 } 448 }); 449 450 menu.addSeparator(); 451 addMenuItem(menu, "Go to...", null); 452 453 menu = new JMenu("Build"); 454 CSH.setHelpIDString(menu, "menus.build"); 455 menuBar.add(menu); 456 menuItem = addMenuItem(menu, "Build", null); 457 menuItem.addActionListener(new ActionListener() { 458 public void actionPerformed(ActionEvent e){ 459 mainHB.showID("build.build", 460 "javax.help.SecondaryWindow", 461 "main"); 462 } 463 }); 464 465 466 menuItem = addMenuItem(menu, "Build All", null); 467 menuItem.addActionListener(new ActionListener() { 468 public void actionPerformed(ActionEvent e){ 469 javax.help.Popup popup = 470 (javax.help.Popup) javax.help.Popup.getPresentation(mainHS, null); 471 popup.setInvoker((Component)e.getSource()); 472 popup.setCurrentID("build.compilefile"); 473 popup.setDisplayed(true); 474 } 475 }); 476 477 menuItem = addMenuItem(menu, "Compile File", null); 478 menuItem.addActionListener(new ActionListener() { 479 public void actionPerformed(ActionEvent e){ 480 mainHB.showID("build.compilefile", 481 "javax.help.MainWindow", 482 "main"); 483 } 484 }); 485 486 menu = new JMenu("Debug"); 487 CSH.setHelpIDString(menu, "menus.debug"); 488 menuBar.add(menu); 489 addMenuItem(menu, "Start/Restart", null); 490 addMenuItem(menu, "Stop", null); 491 492 menu = new JMenu("Window"); 493 CSH.setHelpIDString(menu, "menus.windows"); 494 menuBar.add(menu); 495 496 item1 = menuItem = addMenuItem(menu, "Source", null); 497 item1.addActionListener(this); 498 item2 = menuItem = addMenuItem(menu, "Class Inspector", null); 499 item2.addActionListener(this); 500 501 JMenu help=new JMenu("Help"); 502 CSH.setHelpIDString(help, "menus.help"); 503 if((UIManager.getLookAndFeel().getName()).equals("CDE/Motif")){ 504 menuBar.add(Box.createGlue()); 505 } 506 menuBar.add(help); 507 menu_help=new JMenuItem(helpsetLabel); 508 menu_help.addActionListener(new CSH.DisplayHelpFromSource(mainHB)); 509 help.add(menu_help); 510 help.addSeparator(); 511 512 menu_apihelp=new JMenuItem("Java API Reference"); 513 CSH.setHelpIDString(menu_apihelp, "intro"); 514 menu_apihelp.addActionListener(new CSH.DisplayHelpFromSource(apiHB)); 515 help.add(menu_apihelp); 516 517 menu_apihelp=new JMenuItem("Java API Reference - Secondary Window"); 518 CSH.setHelpIDString(menu_apihelp, "intro"); 519 menu_apihelp.addActionListener(new CSH.DisplayHelpFromSource(apiHS, 520 "javax.help.SecondaryWindow", null)); 521 help.add(menu_apihelp); 522 523 menu_apihelp=new JMenuItem("Java API Reference - Popup"); 524 apiHB.enableHelpOnButton(menu_apihelp, "intro", apiHS, 525 "javax.help.Popup", null); 526 help.add(menu_apihelp); 527 help.addSeparator(); 528 529 if (hasCustomCursor) { 530 JMenuItem menu_cshHelp = new JMenuItem("Help OnItem - Main Window"); 531 menu_cshHelp.addActionListener(new CSH.DisplayHelpAfterTracking(mainHB)); 532 help.add(menu_cshHelp); 533 534 menu_cshHelp = new JMenuItem("Help OnItem - Secondary Window"); 535 menu_cshHelp.addActionListener(new CSH.DisplayHelpAfterTracking(mainHS, "javax.help.SecondaryWindow", "main")); 536 help.add(menu_cshHelp); 537 538 menu_cshHelp = new JMenuItem("Help OnItem - Popup"); 539 menu_cshHelp.addActionListener(new CSH.DisplayHelpAfterTracking(mainHS, "javax.help.Popup", null)); 540 help.add(menu_cshHelp); 541 help.addSeparator(); 542 } 543 544 return menuBar; 545 } 546 actionPerformed(ActionEvent e)547 public void actionPerformed(ActionEvent e) { 548 Object source = e.getSource(); 549 if (source == item1) { 550 try { 551 if (sourceIFrame.isClosed()) { 552 createSourceIFrame(); 553 desktop.add(sourceIFrame, JLayeredPane.PALETTE_LAYER); 554 sourceIFrame.setIcon(false); 555 sourceIFrame.show(); 556 } 557 } catch (PropertyVetoException ex) { 558 // Oh well, ignore 559 } 560 } else if (source == item2) { 561 try { 562 if (classViewerIFrame == null) { 563 createClassViewer(); 564 desktop.add(classViewerIFrame, JLayeredPane.PALETTE_LAYER); 565 classViewerIFrame.setIcon(false); 566 classViewerIFrame.show(); 567 } else if (classViewerIFrame.isClosed()) { 568 desktop.add(classViewerIFrame, JLayeredPane.PALETTE_LAYER); 569 classViewerIFrame.setIcon(false); 570 classViewerIFrame.show(); 571 } 572 } catch (PropertyVetoException ex) { 573 // ignore 574 } 575 } 576 577 if (e.getID() == Event.WINDOW_DESTROY) { 578 frame.dispose(); 579 System.exit(0); 580 } 581 } 582 shiftArgs(String args[], int step)583 private static String[] shiftArgs(String args[], int step) { 584 int count = args.length; 585 String back[] = new String[count-step]; 586 for (int i=0; i<count-step; i++) { 587 back[i] = args[i+step]; 588 } 589 return back; 590 } 591 main(String args[])592 public static void main(String args[]) throws Exception { 593 if (args.length >= 1) { 594 String laf = args[0]; 595 UIManager.setLookAndFeel(swingPkg + laf); 596 args = shiftArgs(args, 1); 597 } 598 599 frame=new JFrame("Java Development Environment"); 600 frame.getContentPane().setLayout(new BorderLayout()); 601 frame.getContentPane().add(new ApiDemo(),"Center"); 602 frame.setBounds(100,100,WIDTH,HEIGHT); 603 frame.show(); 604 } 605 usage()606 static private void usage() { 607 System.err.println("Usage: [laf] [-helpset label name]"); 608 System.exit(1); 609 } 610 611 printData(Container container)612 private static void printData(Container container) { 613 Component k[] = container.getComponents(); 614 for (int i=0; i<k.length; i++) { 615 System.err.println(k[i]); 616 } 617 System.err.println(container); 618 } 619 620 // Static initialization 621 static { 622 Method m = null; 623 hasCustomCursor = false; 624 try { 625 Class types[] = {Image.class, Point.class, String.class}; 626 m = Toolkit.class.getMethod("createCustomCursor", 627 types); 628 if (m != null) { 629 hasCustomCursor = true; 630 } 631 } catch (NoSuchMethodError ex) { 632 // as in JDK1.1 633 } catch (NoSuchMethodException ex) { 634 // as in JDK1.1 635 } 636 } 637 638 } 639 640 641 class FindDialog extends JDialog { 642 private JButton helpButton; 643 private JButton closeButton; 644 private JFrame frame; 645 private ApiDemo demo; 646 initComponents()647 private void initComponents() { 648 649 // playing with Boxes 650 Box topBox = Box.createVerticalBox(); 651 652 Box box1 = Box.createHorizontalBox(); 653 JLabel findLabel = new JLabel("Find: "); 654 JTextField textField = new JTextField(20); 655 box1.add(Box.createHorizontalStrut(5)); 656 box1.add(findLabel); 657 box1.add(textField); 658 box1.add(Box.createHorizontalStrut(5)); 659 660 topBox.add(Box.createVerticalStrut(5)); 661 topBox.add(box1); 662 663 Box box3 = Box.createHorizontalBox(); 664 box3.add(Box.createHorizontalGlue()); 665 JButton findButton = new JButton("Find Next"); 666 JButton prevButton = new JButton("Find Previous"); 667 box3.add(findButton); 668 box3.add(Box.createHorizontalStrut(10)); 669 box3.add(prevButton); 670 box3.add(Box.createHorizontalGlue()); 671 672 topBox.add(box3); 673 674 Box box4 = Box.createHorizontalBox(); 675 Box box5 = Box.createHorizontalBox(); 676 677 JCheckBox backwardsCheck = new JCheckBox("Find Backward"); 678 JCheckBox ignoreCaseCheck = new JCheckBox("Ignore Case"); 679 680 box4.add(Box.createHorizontalGlue()); 681 box4.add(backwardsCheck); 682 box4.add(Box.createHorizontalGlue()); 683 684 box5.add(Box.createHorizontalGlue()); 685 box5.add(ignoreCaseCheck); 686 box5.add(Box.createHorizontalGlue()); 687 688 topBox.add(box4); 689 topBox.add(box5); 690 691 Box box2 = Box.createHorizontalBox(); 692 closeButton = new JButton("Close"); 693 helpButton = new JButton("Help"); 694 695 box2.add(closeButton); 696 box2.add(helpButton); 697 698 Box box6 = Box.createHorizontalBox(); 699 box6.add(Box.createHorizontalStrut(5)); 700 box6.add(new JSeparator()); 701 box6.add(Box.createHorizontalStrut(5)); 702 703 topBox.add(Box.createVerticalStrut(10)); 704 topBox.add(box6); 705 topBox.add(box2); 706 getContentPane().add(topBox); 707 } 708 FindDialog(ApiDemo demo, JFrame f)709 public FindDialog(ApiDemo demo, JFrame f) { 710 super(f, "Find", false); 711 this.frame = f; 712 this.demo = demo; 713 initComponents(); 714 pack(); 715 716 closeButton.addActionListener(new ActionListener() { 717 public void actionPerformed(ActionEvent e) { 718 setVisible(false); 719 dispose(); 720 } 721 }); 722 demo.mainHB.enableHelpOnButton(helpButton, "browse.strings", null); 723 placeDialog(); 724 725 show(); 726 } 727 placeDialog()728 protected void placeDialog() { 729 if (frame != null) { 730 int x = frame.getLocation().x + 30; 731 int y = frame.getLocation().y + 100; 732 setLocation(x, y); 733 } 734 } 735 } 736