@SuppressWarnings("OverridableMethodCallInConstructor") Notepad() { super(true); // Trying to set Nimbus look and feel try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception ignored) { } setBorder(BorderFactory.createEtchedBorder()); setLayout(new BorderLayout()); // create the embedded JTextComponent editor = createEditor(); // Add this as a listener for undoable edits. editor.getDocument().addUndoableEditListener(undoHandler); // install the command table commands = new HashMap<Object, Action>(); Action[] actions = getActions(); for (Action a : actions) { commands.put(a.getValue(Action.NAME), a); } JScrollPane scroller = new JScrollPane(); JViewport port = scroller.getViewport(); port.add(editor); String vpFlag = getProperty("ViewportBackingStore"); if (vpFlag != null) { Boolean bs = Boolean.valueOf(vpFlag); port.setScrollMode(bs ? JViewport.BACKINGSTORE_SCROLL_MODE : JViewport.BLIT_SCROLL_MODE); } JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add("North", createToolbar()); panel.add("Center", scroller); add("Center", panel); add("South", createStatusbar()); }
// ------------------------------------------------------------------------ TextViewer(JFrame inParentFrame) { // super(true); //is double buffered - only for panels textViewerFrame = this; parentFrame = inParentFrame; lastViewedDirStr = ""; lastViewedFileStr = ""; setTitle(resources.getString("Title")); addWindowListener(new AppCloser()); pack(); setSize(500, 600); warningPopup = new WarningDialog(this); okCancelPopup = new WarningDialogOkCancel(this); messagePopup = new MessageDialog(this); okCancelMessagePopup = new MessageDialogOkCancel(this); // Force SwingSet to come up in the Cross Platform L&F try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); // If you want the System L&F instead, comment out the above line and // uncomment the following: // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception exc) { String errstr = "TextViewer:Error loading L&F: " + exc; warningPopup.display(errstr); } Container cf = getContentPane(); cf.setBackground(Color.lightGray); // Border etched=BorderFactory.createEtchedBorder(); // Border title=BorderFactory.createTitledBorder(etched,"TextViewer"); // cf.setBorder(title); cf.setLayout(new BorderLayout()); // create the embedded JTextComponent editor1 = createEditor(); editor1.setFont(new Font("monospaced", Font.PLAIN, 12)); // aa -added next line setPlainDocument((PlainDocument) editor1.getDocument()); // sets doc1 // install the command table commands = new Hashtable(); Action[] actions = getActions(); for (int i = 0; i < actions.length; i++) { Action a = actions[i]; commands.put(a.getValue(Action.NAME), a); // System.out.println("Debug:TextViewer: actionName:"+a.getValue(Action.NAME)); } // editor1.setPreferredSize(new Dimension(,)); // get setting from user preferences if (UserPref.keymapType.equals("Word")) { editor1 = updateKeymapForWord(editor1); } else { editor1 = updateKeymapForEmacs(editor1); } scroller1 = new JScrollPane(); viewport1 = scroller1.getViewport(); viewport1.add(editor1); scroller1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroller1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); try { String vpFlag = resources.getString("ViewportBackingStore"); Boolean bs = new Boolean(vpFlag); viewport1.setBackingStoreEnabled(bs.booleanValue()); } catch (MissingResourceException mre) { System.err.println("TextViewer:missing resource:" + mre.getMessage()); // just use the viewport1 default } menuItems = new Hashtable(); menubar = createMenubar(); lowerPanel = new JPanel(true); // moved double buffering to here lowerPanel.setLayout(new BorderLayout()); lowerPanel.add("North", createToolbar()); lowerPanel.add("Center", scroller1); cf.add("North", menubar); cf.add("Center", lowerPanel); cf.add("South", createStatusbar()); // for the find/search utilities mySearchDialog = new SearchDialog(this); // System.out.println("Debug:TextViewer: end of TextViewer constructor"); }