Exemplo n.º 1
0
@SuppressWarnings("all")
@NonNullByDefault
public interface IHasLineStyle extends org.archstudio.bna.IThing {
  public static final IThingKey<org.archstudio.swtutils.constants.LineStyle> LINE_STYLE_KEY =
      ThingKey.create(
          com.google.common.collect.Lists.newArrayList("lineStyle", IHasLineStyle.class));

  public org.archstudio.swtutils.constants.LineStyle getLineStyle();
}
Exemplo n.º 2
0
public class EditTextLogic extends AbstractThingLogic
    implements IBNAMenuListener, IBNAModelListener, IBNAKeyListener {

  private static final class EditTextLogicData {
    public final Object thingID;

    public EditTextLogicData(Object thingID) {
      this.thingID = thingID;
    }
  }

  private static final IThingKey<EditTextLogicData> DATA_KEY = ThingKey.create(EditTextLogic.class);

  public EditTextLogic() {}

  @Override
  public void fillMenu(
      final IBNAView view, List<IThing> things, final ICoordinate location, IMenuManager m) {
    IThing editThing = null;
    if (Iterables.size(BNAUtils.getSelectedThings(view.getBNAWorld().getBNAModel())) <= 1) {
      MAIN:
      for (IThing thing : things) {
        for (IThing assemblyPartThing :
            Assemblies.getRelatedParts(view.getBNAWorld().getBNAModel(), thing)) {
          if (assemblyPartThing instanceof IHasMutableText
              && UserEditableUtils.isEditableForAnyQualities(
                  assemblyPartThing,
                  IHasMutableText.USER_MAY_EDIT_TEXT,
                  IHasToolTip.USER_MAY_EDIT_TOOL_TIP)) {
            editThing = assemblyPartThing;
            break MAIN;
          }
        }
      }
    }
    final IThing finalThing = editThing;
    if (finalThing != null) {
      m.add(
          new Action("Edit Description...") {

            @Override
            public void run() {
              initEdit(finalThing);
            }
          });
    }
  }

  @Override
  public void keyPressed(IBNAView view, KeyEvent e) {}

  @Override
  public void keyReleased(IBNAView view, KeyEvent e) {
    if (SWT.F2 == e.keyCode) {
      IThing editThing = null;
      if (Iterables.size(BNAUtils.getSelectedThings(view.getBNAWorld().getBNAModel())) == 1) {
        MAIN:
        for (IThing thing : BNAUtils.getSelectedThings(view.getBNAWorld().getBNAModel())) {
          for (IThing assemblyPartThing :
              Assemblies.getRelatedParts(view.getBNAWorld().getBNAModel(), thing)) {
            if (UserEditableUtils.isEditableForAnyQualities(
                assemblyPartThing,
                IHasMutableText.USER_MAY_EDIT_TEXT,
                IHasToolTip.USER_MAY_EDIT_TOOL_TIP)) {
              editThing = assemblyPartThing;
              break MAIN;
            }
          }
        }
      }
      if (editThing != null) {
        initEdit(editThing);
      }
    }
  }

  private void initEdit(IThing forThing) {
    checkNotNull(forThing);

    IBNAModel model = getBNAModel();
    if (model != null) {
      Point p = checkNotNull(BNAUtils.getCentralPoint(forThing));

      SWTTextThing tt = model.addThing(new SWTTextThing(null), forThing);
      tt.set(DATA_KEY, new EditTextLogicData(forThing.getID()));
      String text = "";
      if (forThing instanceof IHasText) {
        text = ((IHasText) forThing).getText();
      } else {
        text = ToolTipLogic.getToolTip(forThing);
      }
      tt.setText(text);
      tt.setBoundingBox(new Rectangle(p.x, p.y, 0, 0));
    }
  }

  @Override
  public void bnaModelChanged(BNAModelEvent evt) {
    if (evt.getEventType() == BNAModelEvent.EventType.THING_REMOVED) {
      EditTextLogicData data = evt.getTargetThing().get(DATA_KEY);
      if (data != null) {
        SWTTextThing tt = (SWTTextThing) evt.getTargetThing();
        IThing t = evt.getSource().getThing(data.thingID);
        if (t instanceof IHasMutableText
            && UserEditableUtils.isEditableForAnyQualities(t, IHasMutableText.USER_MAY_EDIT_TEXT)) {
          BNAOperations.set("Text", getBNAModel(), t, IHasText.TEXT_KEY, tt.getText());
        } else if (t != null
            && UserEditableUtils.isEditableForAnyQualities(t, IHasToolTip.USER_MAY_EDIT_TOOL_TIP)) {
          BNAOperations.set("Text", getBNAModel(), t, IHasToolTip.TOOL_TIP_KEY, tt.getText());
        }
      }
    }
  }
}