コード例 #1
0
ファイル: ViewsPane.java プロジェクト: jjthrash/wordcorr
    public GraphemeClustersRow(BeanCatalog.Property prop, Object obj, final Refreshable refresh) {
      super(prop, obj);
      _view = (View) obj;

      JPanel btnpanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
      _undefineButton =
          new WButton(
              new WordCorrAction("btnGraphemeClusterUndefine", "accGraphemeClusterUndefine") {
                public void actionPerformed(ActionEvent evt) {
                  if (doUndefineGraphemeCluster()) {
                    try {
                      // update list
                      setValue(_view.getGraphemeClusters());
                    } catch (DatabaseException ex) {
                      ex.printStackTrace();
                    }
                  }
                }
              });
      btnpanel.add(_undefineButton, BorderLayout.NORTH);

      JPanel panel = new JPanel(new BorderLayout());
      panel.add(_text, BorderLayout.NORTH);
      panel.add(btnpanel, BorderLayout.CENTER);
      init(panel, _text);
      _text.setFont(FontCache.getIPA());
    }
コード例 #2
0
ファイル: ViewsPane.java プロジェクト: jjthrash/wordcorr
 /** Constructor. */
 public ViewsUndefineGraphemeClusterRow(
     BeanCatalog.Property prop, Object obj, Refreshable refresh) {
   super(prop, obj);
   _data = (UndefineGraphemeClusterTask) obj;
   _refresh = refresh;
   init(_combo, _combo);
   _combo.setFont(FontCache.getIPA());
   refresh();
 }
コード例 #3
0
/** @author Eugene Stahov */
public class ComplexString extends Vector implements VirtualElement {

  // private Vector v;
  public static final int IMAGE = 0x00000000;
  public static final int COLOR = 0x01000000;
  public static final int RALIGN = 0x02000000;
  public static final int UNDERLINE = 0x03000000;
  // #if NICK_COLORS
  // #     public final static int NICK_ON   = 0x04000000;
  // #     public final static int NICK_OFF  = 0x05000000;
  // #endif

  protected Font font = FontCache.getMsgFont();
  private int height;
  private int width;
  private ImageList imageList;
  private int colorBGnd = ColorScheme.LIST_BGND;
  private int color = ColorScheme.LIST_INK;

  /** Creates a new instance of ComplexString */
  public ComplexString() {
    super();
  }

  /** Creates a new instance of ComplexString */
  public ComplexString(ImageList imageList) {
    this();
    this.imageList = imageList;
  }

  private int imgHeight() {
    return (imageList == null) ? 0 : imageList.getHeight();
  }

  private int imgWidth() {
    return (imageList == null) ? 0 : imageList.getWidth();
  }

  public int getColor() {
    return color;
  }

  public int getColorBGnd() {
    return colorBGnd;
  }

  public void setColorBGnd(int color) {
    colorBGnd = color;
  }

  public void setColor(int color) {
    this.color = color;
  }

  public void onSelect() {};

  public void drawItem(Graphics g, int offset, boolean selected, boolean drawsec) {
    // g.setColor(0);
    boolean ralign = false;
    boolean underline = false;

    // #if NICK_COLORS
    // # 	boolean nick=false;
    // #endif

    int w = offset;
    int dw;
    int imageYOfs = ((getVHeight() - imgHeight()) >> 1);
    // #if ALCATEL_FONT
    // #         int fontYOfs=(( getVHeight()-font.getHeight() )>>1) +1;
    // #else
    int fontYOfs = ((getVHeight() - font.getHeight()) >> 1);
    // #endif
    int imgWidth = imgWidth();

    g.setFont(font);
    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          String s = (String) ob;
          // #if NICK_COLORS
          // #                     if (nick) {
          // #                         int color=g.getColor();
          // #                         dw=0;
          // #                         int p1=0;
          // #                         while (p1<s.length()) {
          // #                             int p2=p1;
          // #                             char c1=s.charAt(p1);
          // #                             //processing the same cp
          // #                             while (p2<s.length()) {
          // #                                 char c2=s.charAt(p2);
          // #                                 if ( (c1&0xff00) != (c2 &0xff00) ) break;
          // #                                 p2++;
          // #                             }
          // #                             g.setColor( (c1>255) ? ColorScheme.strong(color) :
          // color);
          // #                             dw=font.substringWidth(s, p1, p2-p1);
          // #                             if (ralign) w-=dw;
          // #                             g.drawSubstring( s, p1, p2-p1,
          // #                                     w,fontYOfs,Graphics.LEFT|Graphics.TOP);
          // #                             if (!ralign) w+=dw;
          // #                             p1=p2;
          // #                         }
          // #
          // #                         g.setColor(color);
          // #                     } else {
          // #endif
          dw = font.stringWidth(s);
          if (ralign) w -= dw;
          g.drawString(s, w, fontYOfs, Graphics.LEFT | Graphics.TOP);
          if (underline) {
            int y = getVHeight() - 1;
            g.drawLine(w, y, w + dw, y);
            underline = false;
          }
          if (!ralign) w += dw;
          // #if NICK_COLORS
          // #                     }
          // #endif

        } else if ((ob instanceof Integer)) {
          // image element or color
          int i = ((Integer) ob).intValue();
          switch (i & 0xff000000) {
            case IMAGE:
              if (imageList == null) break;
              if (ralign) w -= imgWidth;
              imageList.drawImage(g, ((Integer) ob).intValue(), w, imageYOfs);
              if (!ralign) w += imgWidth;
              break;
            case COLOR:
              g.setColor(0xFFFFFF & i);
              break;
            case RALIGN:
              ralign = true;
              w = g.getClipWidth() - 1;
              break;
            case UNDERLINE:
              underline = true;
              break;
              // #if NICK_COLORS
              // #                         case NICK_ON:
              // #                             nick=true;
              // #                             break;
              // #                         case NICK_OFF:
              // #                             nick=false;
              // #                             break;
              // #endif
          }
        } /* Integer*/ else if (ob instanceof VirtualElement) {
          int clipw = g.getClipWidth();
          int cliph = g.getClipHeight();
          ((VirtualElement) ob).drawItem(g, 0, false, false);
          g.setClip(g.getTranslateX(), g.getTranslateY(), clipw, cliph);
          // TODO: рисование не с нулевой позиции и вычисление ширины
        }
      } // if ob!=null
    } // for
  }

  public int getVWidth() {
    // g.setColor(0);
    if (width > 0) return width; // cached

    int w = 0;
    int imgWidth = imgWidth();

    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          w += font.stringWidth((String) ob);
        } else if ((ob instanceof Integer) && imageList != null) {
          // image element or color
          int i = (((Integer) ob).intValue());
          switch (i & 0xff000000) {
            case IMAGE:
              w += imgWidth;
              break;
          }
        } // Integer
      } // if ob!=null
    } // for
    return width = w;
  }

  /*public Object elementAt(int index) {
      if (index<elementCount) return super.elementAt(index);
      return null;
  }*/

  /**
   * Safe version of setElementAt Sets the component at the specified index of this vector to be the
   * specified object. The previous component at that position is discarded. If index is greater or
   * equal to the current size of the vector, size will be automatically enlarged
   *
   * @param obj
   * @param index
   */
  public void setElementAt(Object obj, int index) {
    height = width = 0; // discarding cached values
    if (index >= elementCount) this.setSize(index + 1);
    super.setElementAt(obj, index);
  }

  public int getVHeight() {
    if (height != 0) return height;
    for (int i = 0; i < elementCount; i++) {
      int h = 0;
      Object o = elementData[i];
      if (o == null) continue;
      if (o instanceof String) {
        h = font.getHeight();
      } else if (o instanceof Integer) {
        int a = ((Integer) o).intValue();
        if ((a & 0xff000000) == 0) {
          h = imageList.getWidth();
        }
      } else if (o instanceof VirtualElement) {
        h = ((VirtualElement) o).getVHeight();
      }
      if (h > height) height = h;
    }
    return height;
  }

  public void addElement(Object obj) {
    height = width = 0; // discarding cached values
    super.addElement(obj);
  }

  public void addImage(int imageIndex) {
    addElement(new Integer(imageIndex));
  }

  public void addColor(int colorRGB) {
    addElement(new Integer(COLOR | colorRGB));
  }

  public void addRAlign() {
    addElement(new Integer(RALIGN));
  }

  public void addUnderline() {
    addElement(new Integer(UNDERLINE));
  }

  public Font getFont() {
    return font;
  }

  public void setFont(Font font) {
    this.font = font;
  }

  public String getTipString() {
    return null;
  }

  public String getSecondString() {
    return null;
  }
}