Example #1
0
  private void actualizaTodo() {
    if (!this.controlador.dibujarEscenario()) {
      return;
    }
    int ancho = this.controlador.getAnchoEscenario() * this.pixelesUnidad;
    int alto = this.controlador.getAltoEscenario() * this.pixelesUnidad;
    if ((ancho <= 0) || (alto <= 0)) {
      System.err.println(
          "Error gráfico: el escenario tiene dimensiones negativas. No se actualiza");
      return;
    }
    if ((this.anchoEscenario != ancho) || (this.altoEscenario != alto)) {
      this.anchoEscenario = ancho;
      this.altoEscenario = alto;
      redimensionar();
    }
    Graphics2D original = (Graphics2D) this.escenario.getGraphics();
    VolatileImage buffer = createVolatileImage(this.anchoEscenario, this.altoEscenario);
    Graphics grafico = buffer.getGraphics();

    grafico.setPaintMode();
    grafico.setColor(this.colorSuelo);
    grafico.fillRect(0, 0, this.escenario.getWidth(), this.escenario.getHeight());

    int diametroX = this.controlador.getAnchoEscenario() / 2;
    int diametroY = this.controlador.getAltoEscenario() / 2;
    IRegion region = calcularRegion(diametroX, diametroY);
    IPunto origen = region.getPosicionInferiorIzquierda();

    dibujarCeldas(grafico, region, origen);
    dibujarEntidades(grafico, region, origen);

    original.drawImage(buffer, 0, 0, this);
  }
  protected void copyIndentation(final IDocument d, final DocumentCommand c) {
    // CODE KOPIERT AUS SUPER-KLASSE DA DORT PRIVATE
    // == DefaultIndentLineAutoEditStrategy.autoIndentAfterNewLine(IDocument d, DocumentCommand c)

    if (c.offset == -1 || d.getLength() == 0) return;

    try {
      // find start of line
      int p = (c.offset == d.getLength() ? c.offset - 1 : c.offset);
      IRegion info = d.getLineInformationOfOffset(p);
      int start = info.getOffset();

      // find white spaces
      int end = findEndOfWhiteSpace(d, start, c.offset);

      StringBuffer buf = new StringBuffer(c.text);
      if (end > start) {
        // append to input
        buf.append(d.get(start, end - start));
      }

      c.text = buf.toString();

    } catch (BadLocationException excp) {
      // stop work
    }
  }
  public boolean openHyperLink() {
    String localiz = getLocalization();
    if (localiz == null) {
      return false;
    } else if (fBase.getUnderlyingResource() == null) {
      return false;
    } else if (fElement.length() == 0 || fElement.charAt(0) != '%') {
      return false;
    }

    IProject proj = fBase.getUnderlyingResource().getProject();
    IFile file = proj.getFile(localiz + ".properties"); // $NON-NLS-1$
    if (!file.exists()) return false;

    try {
      IEditorPart editor = IDE.openEditor(PDEPlugin.getActivePage(), file);
      if (!(editor instanceof TextEditor)) return false;
      TextEditor tEditor = (TextEditor) editor;
      IDocument doc = tEditor.getDocumentProvider().getDocument(tEditor.getEditorInput());
      if (doc == null) return false;

      try {
        String key = fElement.substring(1);
        int keyLen = key.length();
        int length = doc.getLength();
        int start = 0;
        IRegion region = null;
        FindReplaceDocumentAdapter docSearch = new FindReplaceDocumentAdapter(doc);
        while ((region = docSearch.find(start, key, true, false, false, false)) != null) {
          int offset = region.getOffset();
          if (offset > 0) {
            // check for newline before
            char c = doc.getChar(offset - 1);
            if (c != '\n' && c != '\r') {
              start += keyLen;
              continue;
            }
          }
          if (offset + keyLen < length) {
            // check for whitespace / assign symbol after
            char c = doc.getChar(offset + keyLen);
            if (!Character.isWhitespace(c) && c != '=' && c != ':') {
              start += keyLen;
              continue;
            }
          }
          tEditor.selectAndReveal(offset, keyLen);
          break;
        }
      } catch (BadLocationException e) {
        PDEPlugin.log(e);
      }

    } catch (PartInitException e) {
      return false;
    }
    return true;
  }
Example #4
0
 public static String[] getRegionNames(IPlottingSystem<?> system, RegionType type) {
   final Collection<IRegion> regions = system.getRegions();
   if (regions == null || regions.size() < 1) return null;
   final List<String> names = new ArrayList<String>(7);
   for (IRegion region : regions) {
     if (type != null && region.getRegionType() != type) continue;
     names.add(region.getName());
   }
   return names.toArray(new String[names.size()]);
 }
Example #5
0
  /**
   * @param plotter
   * @return
   */
  public static Color getUniqueColor(
      IRegion.RegionType type, IRegionSystem plotter, Collection<Color> colours) {

    final Collection<Color> used = new HashSet<Color>(7);
    for (IRegion reg : plotter.getRegions()) {
      if (reg.getRegionType() != type) continue;
      used.add(reg.getRegionColor());
    }

    for (Color color : colours) {
      if (!used.contains(color)) return color;
    }
    return colours.iterator().next();
  }
  /**
   * Internal draw request handler.
   *
   * @param gc Graphics context to update.
   */
  private final void handleDrawRequest(final GC gc) {
    if (mBracketPosition.isDeleted) {
      return;
    }

    int length = mBracketPosition.getLength();
    if (length < 1) {
      return;
    }

    int offset = mBracketPosition.getOffset();
    IRegion region = mSourceViewer.getVisibleRegion();

    if (region.getOffset() <= offset
        && region.getOffset() + region.getLength() >= offset + length) {
      offset -= region.getOffset();
      draw(gc, offset, 1);
    }
  }