예제 #1
0
 public void createNewDocument() {
   view.selectHtmlTab();
   resetDocument();
   view.setTitle("HTML редактор");
   view.resetUndo();
   currentFile = null;
 }
예제 #2
0
 public static void main(String[] args) {
   View viewMain = new View();
   Controller controller = new Controller(viewMain);
   viewMain.setController(controller);
   viewMain.init();
   controller.init();
 }
예제 #3
0
 public void resetDocument() {
   if (document != null) document.removeUndoableEditListener(view.getUndoListener());
   HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
   document = (HTMLDocument) htmlEditorKit.createDefaultDocument();
   document.addUndoableEditListener(view.getUndoListener());
   view.update();
 }
예제 #4
0
 public void dispose() {
   // Dispose of the views
   logger.debug("Disposing of views");
   for (View view : getViews()) {
     view.dispose();
   }
 }
예제 #5
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);
  }
예제 #6
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);
    }
  } // }}}
  /** 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();
  }
예제 #8
0
 public boolean containsView(String id) {
   for (View view : getViews()) {
     if (id.equals(view.getId())) {
       return true;
     }
   }
   return false;
 }
  /** 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);
  }
예제 #10
0
 public void bringViewToFront(String id) {
   for (View view : getViews()) {
     if (view.getId() != null && view.getId().equals(id)) {
       Util.bringToFront(view);
       // Carry on until all views with the specified
       // view id are in front
     }
   }
 }
예제 #11
0
 private View getView(String id, Component c) {
   Collection<View> views = UIUtil.getComponentsExtending(c, View.class);
   for (View view : views) {
     if (view.getId().equals(id)) {
       return view;
     }
   }
   return null;
 }
 @Override
 public GridCellImpl getCellFor(final Content content) {
   // check if the content is already in some cell
   GridCellImpl current = myContent2Cell.get(content);
   if (current != null) return current;
   // view may be shared between several contents with the same ID in different cells
   // (temporary contents like "Dump Stack" or "Console Result")
   View view = getStateFor(content);
   final GridCellImpl cell = myPlaceInGrid2Cell.get(view.getPlaceInGrid());
   assert cell != null : "Unknown place in grid: " + view.getPlaceInGrid().name();
   return cell;
 }
예제 #13
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);
        }
      }
    }
  }
예제 #14
0
 /**
  * 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;
   }
 }
예제 #15
0
  // {{{ userInput() method
  protected void userInput(char ch) {
    lastActionCount = 0;

    JEditTextArea textArea = view.getTextArea();

    /* Buffer buffer = view.getBuffer();
    if(!buffer.insideCompoundEdit())
    	buffer.beginCompoundEdit(); */

    if (repeatCount == 1) textArea.userInput(ch);
    else {
      // stop people doing dumb stuff like C+ENTER 100 C+n
      if (repeatCount > REPEAT_COUNT_THRESHOLD) {
        Object[] pp = {String.valueOf(ch), repeatCount};

        if (GUIUtilities.confirm(
                view,
                "large-repeat-count.user-input",
                pp,
                JOptionPane.WARNING_MESSAGE,
                JOptionPane.YES_NO_OPTION)
            != JOptionPane.YES_OPTION) {
          repeatCount = 1;
          view.getStatus().setMessage(null);
          return;
        }
      }

      JEditBuffer buffer = view.getBuffer();
      try {
        if (repeatCount != 1) buffer.beginCompoundEdit();
        for (int i = 0; i < repeatCount; i++) textArea.userInput(ch);
      } finally {
        if (repeatCount != 1) buffer.endCompoundEdit();
      }
    }

    Macros.Recorder recorder = view.getMacroRecorder();

    if (recorder != null) {
      recorder.recordInput(repeatCount, ch, textArea.isOverwriteEnabled());
    }

    repeatCount = 1;
  } // }}}
예제 #16
0
 public void saveDocumentAs() {
   try {
     view.selectHtmlTab();
     JFileChooser jFileChooser = new JFileChooser();
     jFileChooser.setFileFilter(new HTMLFileFilter());
     jFileChooser.setDialogTitle("Save File");
     int n = jFileChooser.showSaveDialog(view);
     if (n == JFileChooser.APPROVE_OPTION) {
       currentFile = jFileChooser.getSelectedFile();
       view.setTitle(currentFile.getName());
       try (FileWriter writer = new FileWriter(currentFile)) {
         new HTMLEditorKit().write(writer, document, 0, document.getLength());
       }
     }
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
    /**
     * Paints a portion of a highlight.
     *
     * @param g the graphics context
     * @param offs0 the starting model offset &gt;= 0
     * @param offs1 the ending model offset &gt;= offs1
     * @param bounds the bounding box of the view, which is not necessarily the region to paint.
     * @param c the editor
     * @param view View painting for
     * @return region drawing occurred in
     */
    public Shape paintLayer(
        Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) {
      Color color = getColor();

      if (color == null) {
        g.setColor(c.getSelectionColor());
      } else {
        g.setColor(color);
      }

      Rectangle r;

      if (offs0 == view.getStartOffset() && offs1 == view.getEndOffset()) {
        // Contained in view, can just use bounds.
        if (bounds instanceof Rectangle) {
          r = (Rectangle) bounds;
        } else {
          r = bounds.getBounds();
        }
      } else {
        // Should only render part of View.
        try {
          // --- determine locations ---
          Shape shape =
              view.modelToView(offs0, Position.Bias.Forward, offs1, Position.Bias.Backward, bounds);
          r = (shape instanceof Rectangle) ? (Rectangle) shape : shape.getBounds();
        } catch (BadLocationException e) {
          // can't render
          r = null;
        }
      }

      if (r != null) {
        // If we are asked to highlight, we should draw something even
        // if the model-to-view projection is of zero width (6340106).
        r.width = Math.max(r.width, 1);

        g.fillRect(r.x, r.y, r.width, r.height);
      }

      return r;
    }
예제 #18
0
 public void saveDocument() {
   try {
     view.selectHtmlTab();
     if (currentFile != null) {
       try (FileWriter writer = new FileWriter(currentFile)) {
         new HTMLEditorKit().write(writer, document, 0, document.getLength());
       }
     } else saveDocumentAs();
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
예제 #19
0
  // {{{ invokeReadNextChar() method
  protected void invokeReadNextChar(char ch) {
    JEditBuffer buffer = view.getBuffer();

    /* if(buffer.insideCompoundEdit())
    buffer.endCompoundEdit(); */

    String charStr = StandardUtilities.charsToEscapes(String.valueOf(ch));

    // this might be a bit slow if __char__ occurs a lot
    int index;
    while ((index = readNextChar.indexOf("__char__")) != -1) {
      readNextChar =
          readNextChar.substring(0, index)
              + '\''
              + charStr
              + '\''
              + readNextChar.substring(index + 8);
    }

    Macros.Recorder recorder = view.getMacroRecorder();
    if (recorder != null) recorder.record(getRepeatCount(), readNextChar);

    view.getStatus().setMessage(null);

    if (getRepeatCount() != 1) {
      try {
        buffer.beginCompoundEdit();

        BeanShell.eval(
            view,
            BeanShell.getNameSpace(),
            "for(int i = 1; i < " + getRepeatCount() + "; i++)\n{\n" + readNextChar + "\n}");
      } finally {
        buffer.endCompoundEdit();
      }
    } else BeanShell.eval(view, BeanShell.getNameSpace(), readNextChar);

    readNextChar = null;
  } // }}}
  /** 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;
  }
예제 #21
0
  public void openDocument() {
    view.selectHtmlTab();
    JFileChooser fileopen = new JFileChooser();
    fileopen.setFileFilter(new HTMLFileFilter());
    int ret = fileopen.showOpenDialog(view);
    if (ret == JFileChooser.APPROVE_OPTION) {
      currentFile = fileopen.getSelectedFile();
      resetDocument();
      view.setTitle(currentFile.getName());
      try (FileReader reader = new FileReader(currentFile)) {
        new HTMLEditorKit()
            .read(
                reader, document,
                0); // Вызови метод read() из класса HTMLEditorKit, который вычитает данные из
                    // реадера в документ document.

      } catch (Exception e) {
        ExceptionHandler.log(
            e); // Проследи, чтобы метод не кидал исключения. Их необходимо просто логировать.
      }
      view.resetUndo();
    }
  }
예제 #22
0
  /** 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());
  }
예제 #23
0
    public void run() {
      Object tmp;
      Message msg = null;
      int counter = 0;
      Vector v = new Vector();
      while (running) {
        Util.sleep(10);
        try {

          tmp = channel.receive(0);
          if (tmp == null) continue;

          if (tmp instanceof View) {
            View vw = (View) tmp;
            control.viewNumber.setText(String.valueOf(vw.getVid().getId()));
            control.numMessagesInLastView.setText(String.valueOf(counter));
            counter = 0;
            v.clear();
            continue;
          }

          if (!(tmp instanceof Message)) continue;

          msg = (Message) tmp;

          measureThrougput(msg.size());
          TotalPayload p = null;

          p = (TotalPayload) msg.getObject();
          v.addElement(new Integer(p.getRandomSequence()));
          int size = v.size();
          if (size % 50 == 0) {
            int value = 0;
            int i = 0;
            Iterator iter = v.iterator();
            while (iter.hasNext()) {
              i++;
              int seq = ((Integer) iter.next()).intValue();
              if (i % 2 == 0) {
                value *= seq;
              } else if (i % 3 == 0) {
                value -= seq;
              } else value += seq;
            }
            v.clear();
            value = Math.abs(value);
            int r = value % 85;
            int g = value % 170;
            int b = value % 255;
            colorPanel.setSeq(r, g, b);
          }
          counter++;
        } catch (ChannelNotConnectedException e) {
          e.printStackTrace();
        } catch (ChannelClosedException e) {
          e.printStackTrace();
        } catch (TimeoutException e) {
          e.printStackTrace();
        }
      }
    }
예제 #24
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);
      }
    }
  } // }}}
예제 #25
0
 /**
  * Adds a <code>View</code> to the holder.
  *
  * @param view The <code>View</code> to be added.
  */
 public void addView(View view) {
   ViewContainer viewContainer = new ViewContainer(view);
   tabbedHolder.addTab(view.getViewName(), viewContainer);
   tabbedHolder.setSelectedComponent(viewContainer);
 }
예제 #26
0
 public void addView(View view, String label) {
   view.createUI();
   dynamicConfigPanel.setCurrentComponent(view, label);
   dynamicConfigPanel.activate();
 }
예제 #27
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);
            }
          }
        });
  }
  @Override
  protected void paintText(
      Graphics g,
      int tabPlacement,
      Font font,
      FontMetrics metrics,
      int tabIndex,
      String title,
      Rectangle textRect,
      boolean isSelected) {
    g.setFont(font);

    int titleWidth = SwingUtilities.computeStringWidth(metrics, title);

    int preferredWidth = 0;
    if (isOneActionButtonEnabled()) {
      preferredWidth = calculateTabWidth(tabPlacement, tabIndex, metrics) - WIDTHDELTA - 15;

      if (isCloseEnabled()) preferredWidth -= BUTTONSIZE;

      if (isMaxEnabled()) preferredWidth -= BUTTONSIZE;
    } else {
      preferredWidth = titleWidth;
    }

    while (titleWidth > preferredWidth) {
      if (title.endsWith("...")) title = title.substring(0, title.indexOf("...") - 1).concat("...");
      else title = title.substring(0, title.length() - 4).concat("...");

      titleWidth = SwingUtilities.computeStringWidth(metrics, title);
    }

    textRect.width = titleWidth;

    View v = getTextViewForTab(tabIndex);
    if (v != null) {
      // html
      v.paint(g, textRect);
    } else {
      // plain text
      int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

      if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
        if (isSelected) g.setColor(TAB_SELECTED_FOREGROUND_COLOR);
        else {
          if (this.isTabHighlighted(tabIndex)) {
            g.setColor(TAB_HIGHLIGHT_FOREGROUND_COLOR);
          } else g.setColor(tabPane.getForegroundAt(tabIndex));
        }

        BasicGraphicsUtils.drawString(
            g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
      } else { // tab disabled
        g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());

        g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
      }
    }
  }
  /** 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);
  } // }}}
예제 #30
0
 public Double getCurrentAltitude() {
   View view = this.getWWd().getView();
   return view != null ? view.getEyePosition().getElevation() : null;
 }