protected void movePolygon(Point previousMousePoint, Point mousePoint) {
    // Intersect a ray through each mouse point, with a geoid passing through the reference
    // elevation.
    // If either ray fails to intersect the geoid, then ignore this event. Use the difference
    // between the two
    // intersected positions to move the control point's location.

    View view = this.wwd.getView();
    Globe globe = this.wwd.getModel().getGlobe();

    Position refPos = this.polygon.getReferencePosition();
    if (refPos == null) return;

    Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
    Line previousRay =
        view.computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY());

    Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray);
    Vec4 previousVec =
        AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay);

    if (vec == null || previousVec == null) {
      return;
    }

    Position pos = globe.computePositionFromPoint(vec);
    Position previousPos = globe.computePositionFromPoint(previousVec);
    LatLon change = pos.subtract(previousPos);

    this.polygon.move(new Position(change.getLatitude(), change.getLongitude(), 0.0));
  }
  /** Move forward one item in the window history, if possible, and open the view. */
  private void onForward() {

    View view = history.goForward();
    if (view != null) oParent.addViewToDesktop(view, view.getLabel());

    enableHistoryButtons();
  }
  protected void setEyePosition(
      AnimationController animControl,
      View view,
      Position position,
      ViewInputAttributes.ActionAttributes attrib) {

    MoveToPositionAnimator posAnimator =
        (MoveToPositionAnimator) animControl.get(VIEW_ANIM_POSITION);

    double smoothing = attrib.getSmoothingValue();
    if (!(attrib.isEnableSmoothing() && this.isEnableSmoothing())) smoothing = 0.0;

    if (smoothing != 0.0) {

      double elevation =
          ((FlyViewLimits) view.getViewPropertyLimits())
              .limitEyeElevation(position, view.getGlobe());
      if (elevation != position.getElevation()) {
        position = new Position(position, elevation);
      }
      if (posAnimator == null) {
        posAnimator =
            new MoveToPositionAnimator(
                view.getEyePosition(),
                position,
                smoothing,
                OrbitViewPropertyAccessor.createEyePositionAccessor(view));
        animControl.put(VIEW_ANIM_POSITION, posAnimator);
      } else {
        posAnimator.setEnd(position);
        posAnimator.start();
      }
    }
    view.firePropertyChange(AVKey.VIEW, null, view);
  }
示例#4
0
  private void goToSelectedNode(int mode) {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object value = node.getUserObject();

    // do nothing if clicked "foo (showing n occurrences in m files)"
    if (node.getParent() != resultTreeRoot && value instanceof HyperSearchNode) {
      HyperSearchNode n = (HyperSearchNode) value;
      Buffer buffer = n.getBuffer(view);
      if (buffer == null) return;

      EditPane pane;

      switch (mode) {
        case M_OPEN:
          pane = view.goToBuffer(buffer);
          break;
        case M_OPEN_NEW_VIEW:
          pane = jEdit.newView(view, buffer, false).getEditPane();
          break;
        case M_OPEN_NEW_PLAIN_VIEW:
          pane = jEdit.newView(view, buffer, true).getEditPane();
          break;
        case M_OPEN_NEW_SPLIT:
          pane = view.splitHorizontally();
          break;
        default:
          throw new IllegalArgumentException("Bad mode: " + mode);
      }

      n.goTo(pane);
    }
  } // }}}
 protected void onResetHeadingPitchRoll(ViewInputAttributes.ActionAttributes actionAttribs) {
   View view = this.getView();
   if (view == null) // include this test to ensure any derived implementation performs it
   {
     return;
   }
   double smoothing = 0.95;
   this.gotoAnimControl.put(
       VIEW_ANIM_HEADING,
       new RotateToAngleAnimator(
           view.getHeading(),
           Angle.ZERO,
           smoothing,
           ViewPropertyAccessor.createHeadingAccessor(view)));
   this.gotoAnimControl.put(
       VIEW_ANIM_PITCH,
       new RotateToAngleAnimator(
           view.getPitch(),
           Angle.POS90,
           smoothing,
           ViewPropertyAccessor.createPitchAccessor(view)));
   this.gotoAnimControl.put(
       VIEW_ANIM_ROLL,
       new RotateToAngleAnimator(
           view.getPitch(), Angle.ZERO, smoothing, ViewPropertyAccessor.createRollAccessor(view)));
   view.firePropertyChange(AVKey.VIEW, null, view);
 }
示例#6
0
  protected void dragWholeShape(DragSelectEvent dragEvent, Movable dragObject) {
    View view = getWwd().getView();
    EllipsoidalGlobe globe = (EllipsoidalGlobe) getWwd().getModel().getGlobe();

    // Compute ref-point position in screen coordinates.
    Position refPos = dragObject.getReferencePosition();
    if (refPos == null) return;

    Vec4 refPoint = globe.computePointFromPosition(refPos);
    Vec4 screenRefPoint = view.project(refPoint);

    // Compute screen-coord delta since last event.
    int dx = dragEvent.getPickPoint().x - dragEvent.getPreviousPickPoint().x;
    int dy = dragEvent.getPickPoint().y - dragEvent.getPreviousPickPoint().y;

    // Find intersection of screen coord ref-point with globe.
    double x = screenRefPoint.x + dx;
    double y =
        dragEvent.getMouseEvent().getComponent().getSize().height - screenRefPoint.y + dy - 1;
    Line ray = view.computeRayFromScreenPoint(x, y);
    Intersection inters[] = globe.intersect(ray, refPos.getElevation());

    if (inters != null) {
      // Intersection with globe. Move reference point to the intersection point.
      Position p = globe.computePositionFromPoint(inters[0].getIntersectionPoint());
      dragObject.moveTo(p);
    }
  }
示例#7
0
  /** Execute when new member join or leave Group */
  public void viewAccepted(View v) {
    memberSize = v.size();
    if (mainFrame != null) setTitle();
    members.clear();
    members.addAll(v.getMembers());

    if (v instanceof MergeView) {
      System.out.println("** " + v);

      // This is a simple merge function, which fetches the state from the coordinator
      // on a merge and overwrites all of its own state
      if (useState && !members.isEmpty()) {
        Address coord = members.get(0);
        Address local_addr = channel.getAddress();
        if (local_addr != null && !local_addr.equals(coord)) {
          try {

            // make a copy of our state first
            Map<Point, Color> copy = null;
            if (send_own_state_on_merge) {
              synchronized (drawPanel.state) {
                copy = new LinkedHashMap<Point, Color>(drawPanel.state);
              }
            }
            System.out.println("fetching state from " + coord);
            channel.getState(coord, 5000);
            if (copy != null)
              sendOwnState(copy); // multicast my own state so everybody else has it too
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    } else System.out.println("** View=" + v);
  }
  /** Display the forwards window history in a menu. */
  private void onShowForwardHistory() {

    UIScrollableMenu hist =
        new UIScrollableMenu(
            LanguageProperties.getString(
                LanguageProperties.TOOLBARS_BUNDLE, "UIToolBarMain.forwardHistory"),
            0); //$NON-NLS-1$

    Vector views = history.getForwardHistory();
    int currentIndex = history.getCurrentPosition();

    int count = views.size();
    if (count == 0) return;

    JMenuItem item = null;
    for (int i = 0; i < count; i++) {
      View view = (View) views.elementAt(i);
      item = new JMenuItem(view.getLabel());

      final View fview = view;
      final int fi = (currentIndex + 1) + i;
      item.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              if (history.goToHistoryItem(fi)) oParent.addViewToDesktop(fview, fview.getLabel());
            }
          });

      hist.add(item);
    }

    JPopupMenu pop = hist.getPopupMenu();
    pop.pack();

    Point loc = pbShowForwardHistory.getLocation();
    Dimension size = pbShowForwardHistory.getSize();
    Dimension popsize = hist.getPreferredSize();
    Point finalP = SwingUtilities.convertPoint(tbrToolBar.getParent(), loc, oParent.getDesktop());

    int x = 0;
    int y = 0;
    if (oManager.getLeftToolBarController().containsBar(tbrToolBar)) {
      x = finalP.x + size.width;
      y = finalP.y;
    } else if (oManager.getRightToolBarController().containsBar(tbrToolBar)) {
      x = finalP.x - popsize.width;
      y = finalP.y;
    } else if (oManager.getTopToolBarController().containsBar(tbrToolBar)) {
      x = finalP.x;
      y = finalP.y + size.width;
    } else if (oManager.getBottomToolBarController().containsBar(tbrToolBar)) {
      x = finalP.x;
      y = finalP.y - popsize.height;
    }

    hist.setPopupMenuVisible(true);
    pop.show(oParent.getDesktop(), x, y);
  }
  /**
   * Called when the roll changes due to user input.
   *
   * @param rollChange Change in roll.
   * @param actionAttribs Action that caused the change.
   */
  protected void onRoll(Angle rollChange, ViewInputAttributes.ActionAttributes actionAttribs) {
    View view = this.getView();
    if (view == null) // include this test to ensure any derived implementation performs it
    {
      return;
    }

    if (view instanceof BasicFlyView) {
      BasicFlyView flyView = (BasicFlyView) view;
      this.setRoll(flyView, this.uiAnimControl, flyView.getRoll().add(rollChange), actionAttribs);

      view.firePropertyChange(AVKey.VIEW, null, view);
    }
  }
  public void apply() {
    super.apply();

    View view = this.getView();
    if (view == null) {
      return;
    }
    if (this.gotoAnimControl.stepAnimators()) {
      view.firePropertyChange(AVKey.VIEW, null, view);
    }
    if (this.uiAnimControl.stepAnimators()) {
      view.firePropertyChange(AVKey.VIEW, null, view);
    }
  }
示例#11
0
文件: Robots.java 项目: yuan51/CS180
  public void play(int lv) {
    jl.setText("Level " + level);
    Game game = new Game(lv); // An object representing the game
    View view = new View(game); // An object representing the view of the game
    game.newGame();
    view.print();
    gameBoardPanel = view.mainPanel;
    ButtonPanel buttonPanel = new ButtonPanel(game);
    container.add(buttonPanel, BorderLayout.EAST);
    container.add(gameBoardPanel, BorderLayout.WEST);
    mainFrame.pack();

    // Main game loop
    while (true) {

      view.print();
      gameBoardPanel = view.mainPanel;

      // Win/lose conditions
      if (game.isWin()) {
        view.print();
        gameBoardPanel = view.mainPanel;
        int choice;
        choice = JOptionPane.showConfirmDialog(null, "You win!", "", JOptionPane.OK_OPTION);
        if (choice == JOptionPane.OK_OPTION) {
          level++;
          mainFrame.remove(buttonPanel);
          mainFrame.remove(gameBoardPanel);
          play(level);
        }
      }
      if (game.isLose()) {
        view.print();
        gameBoardPanel = view.mainPanel;
        int choice;
        choice =
            JOptionPane.showConfirmDialog(
                null, "You lose!", "Would you like to play again?", JOptionPane.YES_NO_OPTION);
        if (choice == JOptionPane.YES_OPTION) {
          level = 1;
          mainFrame.remove(buttonPanel);
          mainFrame.remove(gameBoardPanel);
          play(level);
        } else {
          System.exit(0);
        }
      }
    }
  }
  protected void onVerticalTranslate(
      double translateChange,
      double totalTranslateChange,
      ViewInputAttributes.DeviceAttributes deviceAttributes,
      ViewInputAttributes.ActionAttributes actionAttribs) {
    this.stopGoToAnimators();
    double elevChange =
        -(totalTranslateChange * getScaleValueElevation(deviceAttributes, actionAttribs));
    View view = this.getView();
    Position position = view.getEyePosition();
    Position newPos = new Position(position, position.getElevation() + (elevChange));
    this.setEyePosition(uiAnimControl, view, newPos, actionAttribs);

    view.firePropertyChange(AVKey.VIEW, null, view);
  }
 /**
  * Establishes the parent view for this view. Seize this moment to cache the AWT Container I'm in.
  */
 public void setParent(View parent) {
   super.setParent(parent);
   fContainer = parent != null ? getContainer() : null;
   if (parent == null && fComponent != null) {
     fComponent.getParent().remove(fComponent);
     fComponent = null;
   }
 }
  protected void onResetPitch(ViewInputAttributes.ActionAttributes actionAttribs) {

    View view = this.getView();
    if (view == null) // include this test to ensure any derived implementation performs it
    {
      return;
    }
    double smoothing = actionAttribs.getSmoothingValue();
    if (!(actionAttribs.isEnableSmoothing() && this.isEnableSmoothing())) smoothing = 0.0;
    this.gotoAnimControl.put(
        VIEW_ANIM_PITCH,
        new RotateToAngleAnimator(
            view.getPitch(),
            Angle.POS90,
            smoothing,
            ViewPropertyAccessor.createPitchAccessor(view)));
    view.firePropertyChange(AVKey.VIEW, null, view);
  }
  protected void onHorizontalTranslateRel(
      Angle forwardChange, Angle sideChange, ViewInputAttributes.ActionAttributes actionAttribs) {
    View view = this.getView();
    if (view == null) // include this test to ensure any derived implementation performs it
    {
      return;
    }

    if (forwardChange.equals(Angle.ZERO) && sideChange.equals(Angle.ZERO)) {
      return;
    }

    if (view instanceof BasicFlyView) {

      Vec4 forward = view.getForwardVector();
      Vec4 up = view.getUpVector();
      Vec4 side = forward.transformBy3(Matrix.fromAxisAngle(Angle.fromDegrees(90), up));

      forward = forward.multiply3(forwardChange.getDegrees());
      side = side.multiply3(sideChange.getDegrees());
      Vec4 eyePoint = view.getEyePoint();
      eyePoint = eyePoint.add3(forward.add3(side));
      Position newPosition = view.getGlobe().computePositionFromPoint(eyePoint);

      this.setEyePosition(this.uiAnimControl, view, newPosition, actionAttribs);
      view.firePropertyChange(AVKey.VIEW, null, view);
    }
  }
  /**
   * Set the roll in a view.
   *
   * @param view View to modify.
   * @param animControl Animator controller for the view.
   * @param roll new roll value.
   * @param attrib action that caused the roll to change.
   */
  protected void setRoll(
      View view,
      AnimationController animControl,
      Angle roll,
      ViewInputAttributes.ActionAttributes attrib) {
    double smoothing = attrib.getSmoothingValue();
    if (!(attrib.isEnableSmoothing() && this.isEnableSmoothing())) smoothing = 0.0;

    AngleAnimator angleAnimator =
        new RotateToAngleAnimator(
            view.getRoll(), roll, smoothing, ViewPropertyAccessor.createRollAccessor(view));
    animControl.put(VIEW_ANIM_ROLL, angleAnimator);
  }
  /** Force a packet to be sent. */
  public void sendPacket() {
    // Also save stuff to a player's local hard-drive.

    if (activationEvent) {
      View MyView = MyHacker.getView();
      Object[] send =
          new Object[] {new Integer(activationID), new Integer(activationType), MyHacker.getIP()};
      MyView.addFunctionCall(
          new RemoteFunctionCall(Hacker.HACKTENDO_PLAYER, "hacktendoActivate", send));
    } else if (targetEvent) {
      View MyView = MyHacker.getView();
      Object[] send = null;
      if (playerSprite != null)
        send =
            new Object[] {
              new Integer(targetX),
              new Integer(targetY),
              MyHacker.getIP(),
              new Integer(playerSprite.getX()),
              new Integer(playerSprite.getY())
            };
      else
        send =
            new Object[] {
              new Integer(targetX),
              new Integer(targetY),
              MyHacker.getIP(),
              new Integer(targetX),
              new Integer(targetY)
            };

      MyView.addFunctionCall(
          new RemoteFunctionCall(Hacker.HACKTENDO_PLAYER, "hacktendoTarget", send));
    }

    activationEvent = false;
    targetEvent = false;
  }
示例#18
0
  protected void moveControlPoint(
      ControlPointMarker controlPoint, Point lastMousePoint, Point moveToPoint) {
    View view = this.wwd.getView();
    Globe globe = this.wwd.getModel().getGlobe();

    Position refPos = controlPoint.getPosition();
    if (refPos == null) return;

    Line ray = view.computeRayFromScreenPoint(moveToPoint.getX(), moveToPoint.getY());
    Line previousRay = view.computeRayFromScreenPoint(lastMousePoint.getX(), lastMousePoint.getY());

    Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray);
    Vec4 previousVec =
        AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay);

    if (vec == null || previousVec == null) {
      return;
    }

    Position pos = globe.computePositionFromPoint(vec);
    Position previousPos = globe.computePositionFromPoint(previousVec);
    LatLon change = pos.subtract(previousPos);

    java.util.List<LatLon> boundary = new ArrayList<LatLon>();
    for (LatLon ll : this.polygon.getOuterBoundary()) {
      boundary.add(ll);
    }

    boundary.set(controlPoint.getIndex(), new Position(pos.add(change), refPos.getAltitude()));

    // ExtrudedPolygon ensures that the last boundary position is the same as the first. Remove the
    // last point
    // before setting the boundary.
    boundary.remove(boundary.size() - 1);

    this.polygon.setOuterBoundary(boundary);
  }
  /** My attributes may have changed. */
  public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    if (DEBUG) System.out.println("ImageView: changedUpdate begin...");
    super.changedUpdate(e, a, f);
    float align = getVerticalAlignment();

    int height = fHeight;
    int width = fWidth;

    initialize(getElement());

    boolean hChanged = fHeight != height;
    boolean wChanged = fWidth != width;
    if (hChanged || wChanged || getVerticalAlignment() != align) {
      if (DEBUG) System.out.println("ImageView: calling preferenceChanged");
      getParent().preferenceChanged(this, hChanged, wChanged);
    }
    if (DEBUG) System.out.println("ImageView: changedUpdate end; valign=" + getVerticalAlignment());
  }
示例#20
0
  // {{{ update() method
  public void update(JMenu menu) {
    final View view = GUIUtilities.getView(menu);

    String path;
    if (dir == null) {
      path = view.getBuffer().getDirectory();
    } else path = dir;

    JMenuItem mi = new JMenuItem(path + ':');
    mi.setActionCommand(path);
    mi.setIcon(FileCellRenderer.openDirIcon);

    // {{{ ActionListeners
    ActionListener fileListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            jEdit.openFile(view, evt.getActionCommand());
          }
        };

    ActionListener dirListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            VFSBrowser.browseDirectory(view, evt.getActionCommand());
          }
        }; // }}}

    mi.addActionListener(dirListener);

    menu.add(mi);
    menu.addSeparator();

    if (dir == null && !(view.getBuffer().getVFS() instanceof FileVFS)) {
      mi = new JMenuItem(jEdit.getProperty("directory.not-local"));
      mi.setEnabled(false);
      menu.add(mi);
      return;
    }

    File directory = new File(path);

    JMenu current = menu;

    // for filtering out backups
    String backupPrefix = jEdit.getProperty("backup.prefix");
    String backupSuffix = jEdit.getProperty("backup.suffix");

    File[] list = directory.listFiles();
    if (list == null || list.length == 0) {
      mi = new JMenuItem(jEdit.getProperty("directory.no-files"));
      mi.setEnabled(false);
      menu.add(mi);
    } else {
      int maxItems = jEdit.getIntegerProperty("menu.spillover", 20);

      Arrays.sort(list, new StandardUtilities.StringCompare<File>(true));
      for (int i = 0; i < list.length; i++) {
        File file = list[i];

        String name = file.getName();

        // skip marker files
        if (name.endsWith(".marks")) continue;

        // skip autosave files
        if (name.startsWith("#") && name.endsWith("#")) continue;

        // skip backup files
        if ((backupPrefix.length() != 0 && name.startsWith(backupPrefix))
            || (backupSuffix.length() != 0 && name.endsWith(backupSuffix))) continue;

        // skip directories
        // if(file.isDirectory())
        //	continue;

        mi = new JMenuItem(name);
        mi.setActionCommand(file.getPath());
        mi.addActionListener(file.isDirectory() ? dirListener : fileListener);
        mi.setIcon(file.isDirectory() ? FileCellRenderer.dirIcon : FileCellRenderer.fileIcon);

        if (current.getItemCount() >= maxItems && i != list.length - 1) {
          // current.addSeparator();
          JMenu newCurrent = new JMenu(jEdit.getProperty("common.more"));
          current.add(newCurrent);
          current = newCurrent;
        }
        current.add(mi);
      }
    }
  } // }}}
示例#21
0
  /**
   * @param restore Ignored unless no views are open
   * @param newView Open a new view?
   * @param newPlainView Open a new plain view?
   * @param parent The client's parent directory
   * @param args A list of files. Null entries are ignored, for convinience
   * @since jEdit 4.2pre1
   */
  public static Buffer handleClient(
      boolean restore, boolean newView, boolean newPlainView, String parent, String[] args) {
    // we have to deal with a huge range of possible border cases here.
    if (jEdit.getFirstView() == null) {
      // coming out of background mode.
      // no views open.
      // no buffers open if args empty.

      boolean hasBufferArgs = false;

      for (String arg : args) {
        if (arg != null) {
          hasBufferArgs = true;
          break;
        }
      }

      boolean restoreFiles =
          restore
              && jEdit.getBooleanProperty("restore")
              && (!hasBufferArgs || jEdit.getBooleanProperty("restore.cli"));

      View view = PerspectiveManager.loadPerspective(restoreFiles);

      Buffer buffer = jEdit.openFiles(view, parent, args);

      if (view == null) {
        if (buffer == null) buffer = jEdit.getFirstBuffer();
        jEdit.newView(null, buffer);
      } else if (buffer != null) view.setBuffer(buffer, false);

      return buffer;
    } else if (newPlainView) {
      // no background mode, and opening a new view
      Buffer buffer = jEdit.openFiles(null, parent, args);
      if (buffer == null) buffer = jEdit.getFirstBuffer();
      jEdit.newView(null, buffer, true);
      return buffer;
    } else if (newView) {
      // no background mode, and opening a new view
      Buffer buffer = jEdit.openFiles(null, parent, args);
      if (buffer == null) buffer = jEdit.getFirstBuffer();
      jEdit.newView(jEdit.getActiveView(), buffer, false);
      return buffer;
    } else {
      // no background mode, and reusing existing view
      View view = jEdit.getActiveView();

      Buffer buffer = jEdit.openFiles(view, parent, args);

      // Hack done to fix bringing the window to the front.
      // At least on windows, Frame.toFront() doesn't cut it.
      // Remove the isWindows check if it's broken under other
      // OSes too.
      if (jEdit.getBooleanProperty("server.brokenToFront")) view.setState(java.awt.Frame.ICONIFIED);

      // un-iconify using JDK 1.3 API
      view.setState(java.awt.Frame.NORMAL);
      view.requestFocus();
      view.toFront();
      // In some platforms (e.g. Windows), only setAlwaysOnTop works
      if (!view.isAlwaysOnTop()) {
        view.setAlwaysOnTop(true);
        view.setAlwaysOnTop(false);
      }
      return buffer;
    }
  } // }}}
示例#22
0
  private void invoke() {
    String cmd;
    if (popup != null) cmd = popup.list.getSelectedValue().toString();
    else {
      cmd = action.getText().trim();
      int index = cmd.indexOf('=');
      if (index != -1) {
        action.addCurrentToHistory();
        String propName = cmd.substring(0, index).trim();
        String propValue = cmd.substring(index + 1).trim();
        String code;

        if (propName.startsWith("buffer.")) {
          if (propName.equals("buffer.mode")) {
            code = "buffer.setMode(\"" + MiscUtilities.charsToEscapes(propValue) + "\");";
          } else {
            code =
                "buffer.setStringProperty(\""
                    + MiscUtilities.charsToEscapes(propName.substring("buffer.".length()))
                    + "\",\""
                    + MiscUtilities.charsToEscapes(propValue)
                    + "\");";
          }

          code += "\nbuffer.propertiesChanged();";
        } else if (propName.startsWith("!buffer.")) {
          code =
              "jEdit.setProperty(\""
                  + MiscUtilities.charsToEscapes(propName.substring(1))
                  + "\",\""
                  + MiscUtilities.charsToEscapes(propValue)
                  + "\");\n"
                  + "jEdit.propertiesChanged();";
        } else {
          code =
              "jEdit.setProperty(\""
                  + MiscUtilities.charsToEscapes(propName)
                  + "\",\""
                  + MiscUtilities.charsToEscapes(propValue)
                  + "\");\n"
                  + "jEdit.propertiesChanged();";
        }

        Macros.Recorder recorder = view.getMacroRecorder();
        if (recorder != null) recorder.record(code);
        BeanShell.eval(view, namespace, code);
        cmd = null;
      } else if (cmd.length() != 0) {
        String[] completions = getCompletions(cmd);
        if (completions.length != 0) {
          cmd = completions[0];
        }
      } else cmd = null;
    }

    if (popup != null) {
      popup.dispose();
      popup = null;
    }

    final String finalCmd = cmd;
    final EditAction act = (finalCmd == null ? null : jEdit.getAction(finalCmd));
    if (temp) view.removeToolBar(this);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            view.getTextArea().requestFocus();
            if (act == null) {
              if (finalCmd != null) {
                view.getStatus()
                    .setMessageAndClear(jEdit.getProperty("view.action.no-completions"));
              }
            } else {
              view.getInputHandler().setRepeatCount(repeatCount);
              view.getInputHandler().invokeAction(act);
            }
          }
        });
  }
示例#23
0
 // {{{ hideDockable() method
 private void hideDockable() {
   view.getDockableWindowManager().hideDockableWindow(NAME);
 } // }}}
  /** Constructor. Sets up and shows the GUI */
  public TextToolsSortDialog(View view, JEditTextArea textArea) {
    super(view, jEdit.getProperty("text-tools.sortadvanced.label"), false);

    this.view = view;
    this.textArea = textArea;
    //		this.data = data;
    //		this.selection = selection;

    view.showWaitCursor();

    sortTableModel = new SortTableModel();

    // preset sortTable if there is a rect selection
    boolean rectSel = false;
    int[] selRows = TextToolsSorting.getRectSelectionRows(textArea);
    if (selRows != null) {
      // we have rectangular selection: assign values to 1st row of table
      sortTableModel.setValueAt(new Integer(selRows[0] + 1), 0, 0);
      sortTableModel.setValueAt(new Integer(selRows[1] + 1), 0, 1);
      rectSel = true;
    }

    sortTable = new JTable(sortTableModel);
    TableColumnModel cMod = sortTable.getColumnModel();
    sortTable.setTableHeader((new SortTableHeader(cMod)));
    sortTable.setRowHeight(25);

    sortTable.setPreferredScrollableViewportSize(new Dimension(430, 200));

    JScrollPane scroll = new JScrollPane(sortTable);

    JPanel content = new JPanel(new BorderLayout());
    content.setBorder(new EmptyBorder(5, 8, 8, 8));
    content.setLayout(new BorderLayout());
    setContentPane(content);
    content.add(scroll, BorderLayout.CENTER);

    JPanel buttons = new JPanel();
    buttons.setBorder(new EmptyBorder(12, 0, 0, 0));
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    buttons.add(Box.createGlue());

    ok = new JButton(jEdit.getProperty("common.ok"));
    ok.addActionListener(this);
    buttons.add(ok);
    buttons.add(Box.createHorizontalStrut(6));
    getRootPane().setDefaultButton(ok);

    cancel = new JButton(jEdit.getProperty("common.cancel"));
    cancel.addActionListener(this);
    buttons.add(cancel);
    buttons.add(Box.createHorizontalStrut(6));

    clear = new JButton("Clear");
    clear.addActionListener(this);
    buttons.add(clear);
    buttons.add(Box.createHorizontalStrut(6));

    help = new JButton("Help");
    help.addActionListener(this);
    buttons.add(help);
    buttons.add(Box.createHorizontalStrut(6));

    buttons.add(Box.createGlue());

    content.add(buttons, BorderLayout.SOUTH);

    delDupsCheckBox =
        new JCheckBox(jEdit.getProperty("text-tools.sortadvanced.delete-identic-lines"));
    onlySelectionCheckBox =
        new JCheckBox(jEdit.getProperty("text-tools.sortadvanced.sort-only-selection"));

    /*
    dontSortCheckBox = new JCheckBox(
    	jEdit.getProperty("text-tools.sortadvanced.dont-sort"));
    delDupsCheckBox.addActionListener(new java.awt.event.ActionListener() {
    	public void actionPerformed(ActionEvent e) {
    		dontSortCheckBox.setEnabled(delDupsCheckBox.isSelected());
    		dontSortCheckBox.setSelected(false);
    	}
    });
    dontSortCheckBox.setEnabled(false);
    */
    JPanel checkBoxes = new JPanel();
    if (rectSel) checkBoxes.add(onlySelectionCheckBox);
    checkBoxes.add(delDupsCheckBox);
    // checkBoxes.add(dontSortCheckBox);  not used, this is an extra action
    content.add(checkBoxes, BorderLayout.NORTH);
    view.hideWaitCursor();
    pack();
    GUIUtilities.loadGeometry(this, "texttools-sort-control");
    setLocationRelativeTo(view);
    setVisible(true);
  } // }}}