Example #1
0
 /**
  * Performs a search.
  *
  * @param sc search context
  * @param jump jump to next hit
  */
 final void search(final SearchContext sc, final boolean jump) {
   try {
     rend.search(sc);
     if (!sc.search.isEmpty()) gui.status.setText(Util.info(Text.STRINGS_FOUND_X, sc.nr()));
     if (jump) jump(SearchDir.CURRENT, false);
   } catch (final Exception ex) {
     final String msg = Util.message(ex).replaceAll(Prop.NL + ".*", "");
     gui.status.setError(Text.REGULAR_EXPR + Text.COLS + msg);
   }
 }
Example #2
0
  /**
   * Draws the specified string.
   *
   * @param g graphics reference
   * @param s text
   * @param x x coordinate
   * @param y y coordinate
   * @param w width
   * @param fs font size
   */
  public static void chopString(
      final Graphics g, final byte[] s, final int x, final int y, final int w, final int fs) {

    if (w < 12) return;
    final int[] cw = fontWidths(g.getFont());

    int j = s.length;
    try {
      int l = 0;
      int fw = 0;
      for (int k = 0; k < j; k += l) {
        final int ww = width(g, cw, cp(s, k));
        if (fw + ww >= w - 4) {
          j = Math.max(1, k - l);
          if (k > 1) fw -= width(g, cw, cp(s, k - 1));
          g.drawString("..", x + fw, y + fs);
          break;
        }
        fw += ww;
        l = cl(s, k);
      }
    } catch (final Exception ex) {
      Util.debug(ex);
    }
    g.drawString(string(s, 0, j), x, y + fs);
  }
Example #3
0
    @Override
    public void execute(final GUI gui) {
      final DialogExport dialog = new DialogExport(gui);
      if (!dialog.ok()) return;

      final IOFile root = new IOFile(dialog.path());

      // check if existing files will be overwritten
      if (root.exists()) {
        IO file = null;
        boolean overwrite = false;
        final Data d = gui.context.data();
        final IntList il = d.resources.docs();
        final int is = il.size();
        for (int i = 0; i < is; i++) {
          file = root.merge(Token.string(d.text(il.get(i), true)));
          if (file.exists()) {
            if (overwrite) {
              // more than one file will be overwritten; check remaining tests
              file = null;
              break;
            }
            overwrite = true;
          }
        }
        if (overwrite) {
          // show message for overwriting files or directories
          final String msg = file == null ? FILES_REPLACE_X : FILE_EXISTS_X;
          if (file == null) file = root;
          if (!BaseXDialog.confirm(gui, Util.info(msg, file))) return;
        }
      }
      DialogProgress.execute(gui, new Export(root.path()));
    }
Example #4
0
  /**
   * Returns a keystroke for the specified string.
   *
   * @param cmd command
   * @return keystroke
   */
  public static KeyStroke keyStroke(final GUICommand cmd) {
    final Object sc = cmd.shortcuts();
    if (sc == null) return null;

    final String scut;
    if (sc instanceof BaseXKeys[]) {
      final BaseXKeys[] scs = (BaseXKeys[]) sc;
      if (scs.length == 0) return null;
      scut = scs[0].shortCut();
    } else {
      scut = Util.info(sc, META);
    }
    final KeyStroke ks = KeyStroke.getKeyStroke(scut);
    if (ks == null) Util.errln("Could not assign shortcut: " + sc + " / " + scut);
    return ks;
  }
Example #5
0
  public VText(SessionShare sshare, ButtonIF vif, String typ) {
    this.vnmrIf = vif;
    setOpaque(false);
    setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    twin = new VTextWin(this, sshare, vif, typ);
    setViewportView(twin);
    JViewport vp = getViewport();
    vp.setBackground(Util.getBgColor());

    orgBg = getBackground();

    ml =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent evt) {
            int clicks = evt.getClickCount();
            int modifier = evt.getModifiers();
            if ((modifier & (1 << 4)) != 0) {
              if (clicks >= 2) {
                ParamEditUtil.setEditObj((VObjIF) evt.getSource());
              }
            }
          }
        };
    new DropTarget(this, this);
    DisplayOptions.addChangeListener(this);
  }
Example #6
0
 /**
  * Set desktop hints (not supported by all platforms).
  *
  * @param g graphics reference
  */
 public static void hints(final Graphics g) {
   if (HINTS != null && hints) {
     try {
       ((Graphics2D) g).addRenderingHints(HINTS);
     } catch (final Exception ex) {
       Util.stack(ex);
       hints = false;
     }
   }
 }
Example #7
0
 /**
  * Returns the clipboard text.
  *
  * @return text
  */
 private static String clip() {
   // copy selection to clipboard
   final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
   final Transferable tr = clip.getContents(null);
   if (tr != null) {
     final ArrayList<Object> contents = BaseXLayout.contents(tr);
     if (!contents.isEmpty()) return contents.get(0).toString();
   } else {
     Util.debug("Clipboard has no contents.");
   }
   return null;
 }
Example #8
0
 /**
  * Returns the width of the specified text. Cached font widths are used to speed up calculation.
  *
  * @param g graphics reference
  * @param s string to be evaluated
  * @return string width
  */
 public static int width(final Graphics g, final byte[] s) {
   final int[] cw = fontWidths(g.getFont());
   final int l = s.length;
   int fw = 0;
   try {
     // ignore faulty character sets
     for (int k = 0; k < l; k += cl(s, k)) fw += width(g, cw, cp(s, k));
   } catch (final Exception ex) {
     Util.debug(ex);
   }
   return fw;
 }
Example #9
0
 /** Reads in the property file. */
 static {
   try {
     final String file = "/completions.properties";
     final InputStream is = TextPanel.class.getResourceAsStream(file);
     if (is == null) {
       Util.errln(file + " not found.");
     } else {
       try (final NewlineInput nli = new NewlineInput(is)) {
         for (String line; (line = nli.readLine()) != null; ) {
           final int i = line.indexOf('=');
           if (i == -1 || line.startsWith("#")) continue;
           final String key = line.substring(0, i), value = line.substring(i + 1);
           if (REPLACE.put(key, value.replace("\\n", "\n")) != null) {
             Util.errln(file + ": " + key + " was assigned twice");
           }
         }
       }
     }
   } catch (final IOException ex) {
     Util.errln(ex);
   }
 }
Example #10
0
 private void setBorder(boolean isEnabled) {
   JTextField txfTmp = new JTextField();
   if (isEnabled) setBorder(txfTmp.getBorder());
   else {
     String strStyle = getAttribute(DISABLE);
     if (strStyle != null && strStyle.equals(m_arrStrDisAbl[1])) {
       setBorder(null);
       setBackground(Util.getBgColor());
     } else {
       setBorder(txfTmp.getBorder());
       setBackground(Global.NPCOLOR);
     }
   }
 }
Example #11
0
 /**
  * Replaces the text.
  *
  * @param rc replace context
  */
 final void replace(final ReplaceContext rc) {
   try {
     final int[] select = rend.replace(rc);
     if (rc.text != null) {
       final boolean sel = editor.selected();
       setText(rc.text);
       editor.select(select[0], select[sel ? 1 : 0]);
       release(Action.CHECK);
     }
     gui.status.setText(Text.STRINGS_REPLACED);
   } catch (final Exception ex) {
     final String msg = Util.message(ex).replaceAll(Prop.NL + ".*", "");
     gui.status.setError(Text.REGULAR_EXPR + Text.COLS + msg);
   }
 }
Example #12
0
 /**
  * Returns the contents of the specified transferable.
  *
  * @param tr transferable
  * @return contents
  */
 @SuppressWarnings("unchecked")
 public static ArrayList<Object> contents(final Transferable tr) {
   final ArrayList<Object> list = new ArrayList<>();
   try {
     if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
       for (final File fl : (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor))
         list.add(fl);
     } else if (tr.isDataFlavorSupported(DataFlavor.stringFlavor)) {
       list.add(tr.getTransferData(DataFlavor.stringFlavor));
     }
   } catch (final Exception ex) {
     Util.stack(ex);
   }
   return list;
 }
Example #13
0
  /**
   * Adds default interactions to the specified component.
   *
   * @param comp component
   * @param win parent window
   */
  public static void addInteraction(final Component comp, final Window win) {
    comp.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseEntered(final MouseEvent e) {
            focus(comp);
          }
        });

    if (win instanceof BaseXDialog) {
      // add default keys
      final BaseXDialog d = (BaseXDialog) win;
      comp.addKeyListener(
          new KeyAdapter() {
            @Override
            public void keyPressed(final KeyEvent e) {
              final Object s = e.getSource();
              if (s instanceof BaseXCombo && ((BaseXCombo) s).isPopupVisible()) return;

              // do not key close dialog if button or editor is focused
              if (ENTER.is(e) && !(s instanceof BaseXButton || s instanceof TextPanel)) {
                d.close();
              } else if (ESCAPE.is(e)) {
                // do not cancel dialog if search bar is opened
                boolean close = true;
                if (s instanceof TextPanel) {
                  final SearchBar bar = ((TextPanel) s).getSearch();
                  close = bar == null || !bar.deactivate(true);
                }
                if (close) d.cancel();
              }
            }
          });
      return;
    }

    if (win instanceof GUI) {
      comp.addKeyListener(globalShortcuts((GUI) win));
    } else {
      throw Util.notExpected("Reference to main window expected.");
    }
  }
Example #14
0
 public void setAttribute(int attr, String c) {
   switch (attr) {
     case TYPE:
       type = c;
       break;
     case FGCOLOR:
       fg = c;
       fgColor = DisplayOptions.getColor(fg);
       setForeground(fgColor);
       repaint();
       break;
     case BGCOLOR:
       if (!DisplayOptions.isOption(DisplayOptions.COLOR, c)) c = null;
       bg = c;
       if (c != null) {
         bgColor = DisplayOptions.getColor(c);
         setOpaque(true);
       } else {
         bgColor = Util.getBgColor();
         if (isActive < 1) setOpaque(true);
         else setOpaque(inEditMode);
       }
       setBackground(bgColor);
       repaint();
       break;
     case COLOR2:
       caretColor = c;
       if (DisplayOptions.isOption(DisplayOptions.COLOR, c)) {
         Color col = DisplayOptions.getColor(c);
         setCaretColor(col);
         setSelectionColor(col);
       }
       break;
     case SHOW:
       showVal = c;
       setBorder(isEnabled);
       break;
     case FONT_NAME:
       fontName = c;
       break;
     case FONT_STYLE:
       fontStyle = c;
       break;
     case FONT_SIZE:
       fontSize = c;
       break;
     case SETVAL:
       setVal = c;
       break;
     case SETVAL2:
       caretQuery = c;
       break;
     case VARIABLE:
       vnmrVar = c;
       break;
     case CMD:
       vnmrCmd = c;
       break;
     case CMD2:
       caretCmd = c;
       break;
     case NUMDIGIT:
       precision = c;
       break;
     case LABEL:
       label = c;
       break;
     case VALUE:
       value = c;
       setText(c);
       break;
     case KEYSTR:
       keyStr = c;
       break;
     case KEYVAL:
       setText(c);
       break;
     case DISABLE:
       m_strDisAbl = c;
       break;
   }
 }
Example #15
0
 public void propertyChange(PropertyChangeEvent evt) {
   JViewport vp = getViewport();
   if (vp != null) vp.setBackground(Util.getBgColor());
 }