Exemplo n.º 1
0
 /**
  * This is the hook through which all menu items are created. It registers the result with the
  * menuitem hashtable so that it can be fetched with getMenuItem().
  *
  * @see #getMenuItem
  */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getResourceString(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action myaction = getAction(astr); // if this is a known action
   if (myaction != null) {
     mi.addActionListener(myaction);
     myaction.addPropertyChangeListener(createActionChangeListener(mi));
     // System.out.println("myaction not null: astr:"+astr+" enabled:"+myaction.isEnabled());
     mi.setEnabled(myaction.isEnabled());
   } else {
     System.err.println("Error:TextViewer: createMenuItem: myaction is null: astr:" + astr);
     // causes the item to be greyed out
     mi.setEnabled(false);
   }
   menuItems.put(cmd, mi);
   return mi;
 }
Exemplo n.º 2
0
 @Override
 public void ioResult(IOServiceEvent e) {
   if (e.getState() == IOServiceEvent.MOUNT_SUCCESS
       || e.getState() == IOServiceEvent.MOUNT_FAILURE) {
     lumberjack.setFullModel(buildModel(e.getResolverBundle().getResolvers()));
     toggleAction.setEnabled(cpos != null);
     toggleAction.putValue(
         Action.SELECTED_KEY,
         (Boolean) toggleAction.getValue(Action.SELECTED_KEY) && cpos != null);
   }
 }
Exemplo n.º 3
0
 /** Configures a JCheckBoxMenuItem for an Action. */
 public static void configureJCheckBoxMenuItem(final JCheckBoxMenuItem mi, final Action a) {
   mi.setSelected((Boolean) a.getValue(Actions.SELECTED_KEY));
   PropertyChangeListener propertyHandler =
       new PropertyChangeListener() {
         public void propertyChange(PropertyChangeEvent evt) {
           if (evt.getPropertyName().equals(Actions.SELECTED_KEY)) {
             mi.setSelected((Boolean) a.getValue(Actions.SELECTED_KEY));
           }
         }
       };
   a.addPropertyChangeListener(propertyHandler);
   mi.putClientProperty("actionPropertyHandler", propertyHandler);
 }
Exemplo n.º 4
0
  @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());
  }
Exemplo n.º 5
0
 /** Unconfigures a JCheckBoxMenuItem for an Action. */
 public static void unconfigureJCheckBoxMenuItem(JCheckBoxMenuItem mi, Action a) {
   PropertyChangeListener propertyHandler =
       (PropertyChangeListener) mi.getClientProperty("actionPropertyHandler");
   if (propertyHandler != null) {
     a.removePropertyChangeListener(propertyHandler);
     mi.putClientProperty("actionPropertyHandler", null);
   }
 }
Exemplo n.º 6
0
 public Action getNewFolderAction() {
   if (newFolderAction == null) {
     newFolderAction = new NewFolderAction();
     // Note: Don't return null for readOnly, it might
     // break older apps.
     if (readOnly) {
       newFolderAction.setEnabled(false);
     }
   }
   return newFolderAction;
 }
Exemplo n.º 7
0
 /** This is the hook through which all menu items are created. */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getProperty(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action a = getAction(astr);
   if (a != null) {
     mi.addActionListener(a);
     a.addPropertyChangeListener(createActionChangeListener(mi));
     mi.setEnabled(a.isEnabled());
   } else {
     mi.setEnabled(false);
   }
   return mi;
 }
Exemplo n.º 8
0
 /**
  * Unlinks an {@link visad.Action} from the data component.
  *
  * @param action The {@link visad.Action} to be unlinked.
  * @throws VisADException VisAD failure.
  * @throws RemoteException Java RMI failure.
  */
 public synchronized void removeAction(Action action) throws VisADException, RemoteException {
   action.removeReference(dataReference);
 }
Exemplo n.º 9
0
 /**
  * Links an {@link visad.Action} to the data component.
  *
  * @param action The {@link visad.Action} to be linked.
  * @throws VisADException VisAD failure.
  * @throws RemoteException Java RMI failure.
  */
 public synchronized void addAction(Action action) throws VisADException, RemoteException {
   action.addReference(dataReference);
 }
Exemplo n.º 10
0
  // ------------------------------------------------------------------------
  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");

  }