Пример #1
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);
  }
Пример #2
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;
  }
Пример #3
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);
  }
Пример #4
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;
     }
   }
 }
Пример #5
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;
 }
Пример #6
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);
     }
   }
 }
Пример #7
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;
 }
Пример #8
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.");
    }
  }
Пример #9
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;
   }
 }
Пример #10
0
 public void propertyChange(PropertyChangeEvent evt) {
   JViewport vp = getViewport();
   if (vp != null) vp.setBackground(Util.getBgColor());
 }