Example #1
0
  /**
   * Installs a Tool in the Toolbar
   *
   * @param toolbar as JToolbar
   * @param tool, Tool to install
   */
  public void installToolInToolBar(JToolBar toolbar, final Tool tool) {
    final JButton button;
    button = new JButton();

    button.setMargin(new Insets(0, 0, 0, 0));

    if (tool.getItemType() != null) {
      button.setIcon(tool.getItemType().getIcon());
      button.setToolTipText(tool.getItemType().getDescription());

    } else {
      button.setText("Tool"); // For Debugging
    }
    toolbar.add(button);
    toolButtons.add(button);
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            WorkingView.this.setTool(tool, button);
          }
        });
    button.setContentAreaFilled(false);
    button.setBorderPainted(false);
    button.addMouseListener(
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            ((JButton) e.getSource()).setBorderPainted(true);
          }

          public void mouseExited(MouseEvent e) {
            ((JButton) e.getSource()).setBorderPainted(false);
          }
        });
  }
Example #2
0
  public ToolButton(PaletteListener listener, String iconName, String name, Tool tool) {
    super(listener);
    tool.addToolListener(this);
    setEnabled(tool.isUsable());

    // use a Mediatracker to ensure that all the images are initially loaded
    Iconkit kit = Iconkit.instance();
    if (kit == null) {
      throw new JHotDrawRuntimeException("Iconkit instance isn't set");
    }

    Image im[] = new Image[3];
    im[0] = kit.loadImageResource(iconName + "1.gif");
    im[1] = kit.loadImageResource(iconName + "2.gif");
    im[2] = kit.loadImageResource(iconName + "3.gif");

    MediaTracker tracker = new MediaTracker(this);
    for (int i = 0; i < 3; i++) {
      tracker.addImage(im[i], i);
    }
    try {
      tracker.waitForAll();
    } catch (Exception e) {
      // ignore exception
    }

    fIcon = new PaletteIcon(new Dimension(24, 24), im[0], im[1], im[2]);
    fTool = tool;
    fName = name;

    setIcon(new ImageIcon(im[0]));
    setPressedIcon(new ImageIcon(im[1]));
    setSelectedIcon(new ImageIcon(im[2]));
    setToolTipText(name);
  }
Example #3
0
 /** Loads the image resources. */
 public void initResources() {
   final Class clazz = PaintExample.class;
   if (PaintExample.resourceBundle != null)
     try {
       for (int i = 0; i < PaintExample.tools.length; ++i) {
         Tool tool = PaintExample.tools[i];
         String id = tool.group + '.' + tool.name;
         InputStream sourceStream =
             clazz.getResourceAsStream(PaintExample.getResourceString(id + ".image"));
         ImageData source = new ImageData(sourceStream);
         ImageData mask = source.getTransparencyMask();
         tool.image = new Image(null, source, mask);
         try {
           sourceStream.close();
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
       return;
     } catch (Throwable t) {
     }
   String error =
       PaintExample.resourceBundle != null
           ? PaintExample.getResourceString("error.CouldNotLoadResources")
           : "Unable to load resources";
   freeResources();
   throw new RuntimeException(error);
 }
Example #4
0
  private LinearLayout getTitleView(Context context, AlertType type) {
    this.context = context;

    LinearLayout mainLine = new LinearLayout(context);
    mainLine.setOrientation(LinearLayout.HORIZONTAL);
    LayoutParams layoutParams =
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    mainLine.setLayoutParams(layoutParams);
    mainLine.setPadding(
        Tool.dip2px(context, 10),
        Tool.dip2px(context, 10),
        Tool.dip2px(context, 10),
        Tool.dip2px(context, 10));
    mainLine.setGravity(Gravity.CENTER_VERTICAL);

    mainLine.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.toast_background));

    ImageView imageView = new ImageView(context);
    if (type == AlertType.ERR) {
      imageView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.err));
    } else if (type == AlertType.INFO) {
      imageView.setBackgroundDrawable(
          context.getResources().getDrawable(R.drawable.radio_bt_selected));
    } else {
      imageView.setBackgroundDrawable(null);
    }
    mainLine.addView(imageView);

    textView = new TextView(context);
    textView.setTextColor(context.getResources().getColor(R.color.white));

    textView.setTextSize(16);
    mainLine.addView(textView);
    return mainLine;
  }
 @Override
 public void actionPerformed(ActionEvent e) {
   for (Options option : Options.values())
     if (e.getActionCommand().equals(option.getCaption())) this.option = option;
   for (Tool tool : Tool.values())
     if (e.getActionCommand().equals(tool.name())) {
       try {
         Method m = BusLaneAdderWindow.class.getMethod(tool.function, new Class[] {});
         m.invoke(this, new Object[] {});
       } catch (SecurityException e1) {
         e1.printStackTrace();
       } catch (NoSuchMethodException e1) {
         e1.printStackTrace();
       } catch (IllegalArgumentException e1) {
         e1.printStackTrace();
       } catch (IllegalAccessException e1) {
         e1.printStackTrace();
       } catch (InvocationTargetException e1) {
         e1.printStackTrace();
       }
       setVisible(true);
       repaint();
     }
   if (e.getActionCommand().equals(READY_TO_EXIT)) {
     setVisible(false);
     readyToExit = true;
   }
 }
  private void editSelected() {
    CheckedTreeNode node = getSelectedToolNode();
    if (node != null && node.getUserObject() instanceof Tool) {
      Tool selected = (Tool) node.getUserObject();
      if (selected != null) {
        String oldGroupName = selected.getGroup();
        ToolEditorDialog dlg = new ToolEditorDialog(this);
        dlg.setData(selected, getGroups());
        dlg.show();
        if (dlg.isOK()) {
          selected.copyFrom(dlg.getData());
          String newGroupName = selected.getGroup();
          if (!Comparing.equal(oldGroupName, newGroupName)) {
            CheckedTreeNode oldGroupNode = (CheckedTreeNode) node.getParent();
            removeNodeFromParent(node);
            ((ToolsGroup) oldGroupNode.getUserObject()).removeElement(selected);
            if (oldGroupNode.getChildCount() == 0) {
              removeNodeFromParent(oldGroupNode);
            }

            insertNewTool(selected, true);
          } else {
            (getModel()).nodeChanged(node);
          }
          myIsModified = true;
          update();
        }
      }
    }
  }
Example #7
0
  @Override
  public boolean hasCustomSettings() {
    IResourceInfo parentRc = getParentResourceInfo();
    if (parentRc instanceof FolderInfo) {
      IPath path = getPath();
      String ext = path.getFileExtension();
      if (ext == null) ext = ""; // $NON-NLS-1$
      ITool otherTool = ((FolderInfo) parentRc).getToolFromInputExtension(ext);
      if (otherTool == null) return true;

      ITool[] tti = getToolsToInvoke();
      if (tti.length != 1) return true;

      return ((Tool) tti[0]).hasCustomSettings((Tool) otherTool);
    }
    ITool[] tools = getTools();
    ITool[] otherTools = ((IFileInfo) parentRc).getTools();
    if (tools.length != otherTools.length) return true;

    for (int i = 0; i < tools.length; i++) {
      Tool tool = (Tool) tools[i];
      Tool otherTool = (Tool) otherTools[i];
      if (tool.hasCustomSettings(otherTool)) return true;
    }

    return false;
  }
Example #8
0
  public Tool createTool(Class<? extends Tool> toolClass) {
    Tool tool;
    try {
      Constructor<? extends Tool> constructor = toolClass.getDeclaredConstructor(new Class[] {});
      tool = constructor.newInstance(new Object[] {});
      //			tool = constructor.newInstance((Object) null);

      buttonGroup.add(tool);
      toolMap.put(toolClass, tool);
      tool.setToolbox(this);
      return tool;
    } catch (InstantiationException e) {
      TabletopTool.showError(
          I18N.getText("msg.error.toolCannotInstantiate", toolClass.getName()), e);
    } catch (IllegalAccessException e) {
      TabletopTool.showError(
          I18N.getText("msg.error.toolNeedPublicConstructor", toolClass.getName()), e);
    } catch (NoSuchMethodException nsme) {
      TabletopTool.showError(
          I18N.getText("msg.error.toolNeedValidConstructor", toolClass.getName()), nsme);
    } catch (InvocationTargetException ite) {
      TabletopTool.showError(
          I18N.getText("msg.error.toolConstructorFailed", toolClass.getName()), ite);
    }
    return null;
  }
Example #9
0
 public void setSelectedTool(Class<? extends Tool> toolClass) {
   Tool tool = toolMap.get(toolClass);
   if (tool != null && tool.isAvailable()) {
     tool.setSelected(true);
     setSelectedTool(tool);
   }
 }
Example #10
0
 @Override
 public boolean isSeparatorNeeded(final Tool tool1, final Tool tool2) {
   if (tool1 == null || tool2 == null) return false;
   final double priority1 = tool1.getInfo().getPriority();
   final double priority2 = tool2.getInfo().getPriority();
   return Math.abs(priority1 - priority2) >= SEPARATOR_DISTANCE;
 }
Example #11
0
  /** Handles mouse down events and starts the corresponding tracker. */
  public void mouseDown(MouseEvent e, int x, int y) {
    // on MS-Windows NT: AWT generates additional mouse down events
    // when the left button is down && right button is clicked.
    // To avoid dead locks we ignore such events
    if (fChild != null) {
      return;
    }

    view().freezeView();

    Handle handle = view().findHandle(e.getX(), e.getY());
    if (handle != null) {
      fChild = createHandleTracker(view(), handle);
    } else {
      Figure figure = drawing().findFigure(e.getX(), e.getY());
      if (figure != null) {
        fChild = createDragTracker(figure);
      } else {
        if (!e.isShiftDown()) {
          view().clearSelection();
        }
        fChild = createAreaTracker();
      }
    }
    fChild.mouseDown(e, x, y);
    fChild.activate();
  }
Example #12
0
  private LayoutParams getCurLayoutParams() {

    LinearLayout.LayoutParams layoutParams =
        new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, Tool.dip2px(getContext(), 35));
    layoutParams.topMargin = Tool.dip2px(getContext(), 1);
    return layoutParams;
  }
 /**
  * Sets the active Tool for this EditDomain. If a current Tool is active, it is deactivated. The
  * new Tool is told its EditDomain, and is activated.
  *
  * @param tool the Tool
  */
 public void setActiveTool(Tool tool) {
   if (activeTool != null) activeTool.deactivate();
   activeTool = tool;
   if (activeTool != null) {
     activeTool.setEditDomain(this);
     activeTool.activate();
   }
 }
Example #14
0
 public String getGroupByActionId(String actionId) {
   for (Tool tool : getTools()) {
     if (Comparing.equal(actionId, tool.getActionId())) {
       return tool.getGroup();
     }
   }
   return null;
 }
Example #15
0
 public int[] addSymetricRankXandY(int[] inputRank) {
   ArrayList<Integer> theList = new ArrayList<Integer>();
   int[] theArray = new int[inputRank.length];
   theList = Tool.array2List(inputRank);
   theList = addSymetricRankXandY(theList);
   theArray = Tool.list2Array(theList);
   return (theArray);
 }
Example #16
0
 /** Handles mouse up events. The events are forwarded to the current tracker. */
 public void mouseUp(MouseEvent e, int x, int y) {
   view().unfreezeView();
   if (fChild != null) { // JDK1.1 doesn't guarantee mouseDown, mouseDrag, mouseUp
     fChild.mouseUp(e, x, y);
     fChild.deactivate();
     fChild = null;
   }
 }
Example #17
0
 /** Frees the resource bundle resources. */
 public void freeResources() {
   for (int i = 0; i < PaintExample.tools.length; ++i) {
     Tool tool = PaintExample.tools[i];
     final Image image = tool.image;
     if (image != null) image.dispose();
     tool.image = null;
   }
 }
Example #18
0
  public ToolBelt(String configFile) throws FitsConfigurationException {
    XMLConfiguration config = null;
    try {
      config = new XMLConfiguration(configFile);
    } catch (ConfigurationException e) {
      throw new FitsConfigurationException("Error reading " + configFile, e);
    }

    // Collect the tools-used elements
    List<ToolsUsedItem> toolsUsedList = processToolsUsed(config);

    tools = new ArrayList<Tool>();

    // get number of tools
    int size = config.getList("tools.tool[@class]").size();
    // for each tools get the class path and any excluded extensions
    for (int i = 0; i < size; i++) {
      String tClass = config.getString("tools.tool(" + i + ")[@class]");
      @SuppressWarnings("unchecked")
      List<String> excludes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@exclude-exts]");
      @SuppressWarnings("unchecked")
      List<String> includes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@include-exts]");
      Tool t = null;
      try {
        @SuppressWarnings("rawtypes")
        Class c = Class.forName(tClass);
        t = (Tool) c.newInstance();
      } catch (Exception e) {
        // Can't use this tool, but continue anyway.
        // throw new FitsConfigurationException("Error initializing "+tClass,e);
        logger.error(
            "Thread "
                + Thread.currentThread().getId()
                + " error initializing "
                + tClass
                + ": "
                + e.getClass().getName()
                + "  Message: "
                + e.getMessage());
        continue;
      }
      if (t != null) {
        t.setName(bareClassName(tClass));
        for (String ext : excludes) {
          t.addExcludedExtension(ext);
        }
        for (String ext : includes) {
          t.addIncludedExtension(ext);
        }
        // Modify included and excluded extensions by tools-used
        t.applyToolsUsed(toolsUsedList);
        tools.add(t);
      }
    }
  }
 private static Tool findTool(String actionId, DataContext context) {
   MacroManager.getInstance().cacheMacrosPreview(context);
   for (Tool tool : getAllTools()) {
     if (actionId.equals(tool.getActionId())) {
       return tool;
     }
   }
   return null;
 }
  /** Initializes {@link #tools}. */
  private synchronized void initTools() {
    if (tools != null) return; // already initialized

    final HashMap<String, Tool> map = new HashMap<String, Tool>();
    for (final Tool tool : toolList()) {
      map.put(tool.getInfo().getName(), tool);
    }

    tools = map;
  }
Example #21
0
 @EventHandler
 protected void onEvent(final KyReleasedEvent event) {
   if (event.isConsumed()) return;
   final Tool aTool = getActiveTool();
   if (eventOk(event, aTool)) aTool.onKeyUp(event);
   for (final Tool tool : getAlwaysActiveTools()) {
     if (event.isConsumed()) break;
     if (eventOk(event, tool)) tool.onKeyUp(event);
   }
 }
Example #22
0
 @EventHandler
 protected void onEvent(final MsWheelEvent event) {
   if (event.isConsumed()) return;
   final Tool aTool = getActiveTool();
   if (eventOk(event, aTool)) aTool.onMouseWheel(event);
   for (final Tool tool : getAlwaysActiveTools()) {
     if (event.isConsumed()) break;
     if (eventOk(event, tool)) tool.onMouseWheel(event);
   }
 }
Example #23
0
 private void setTool(Tool t, String name) {
   if (fTool != null) {
     fTool.deactivate();
   }
   fTool = t;
   if (fTool != null) {
     showStatus(name);
     fTool.activate();
   }
 }
Example #24
0
 /** Get all not empty group names of tools in array */
 String[] getGroups(Tool[] tools) {
   ArrayList<String> list = new ArrayList<String>();
   for (int i = 0; i < tools.length; i++) {
     Tool tool = tools[i];
     if (!list.contains(tool.getGroup())) {
       list.add(tool.getGroup());
     }
   }
   return ArrayUtil.toStringArray(list);
 }
  /** Initializes {@link #toolList}. */
  private synchronized void initToolList() {
    if (toolList != null) return; // already initialized

    final ArrayList<Tool> list = new ArrayList<Tool>();
    for (final Tool tool : getInstances()) {
      if (tool.isAlwaysActive()) continue;
      list.add(tool);
    }

    toolList = list;
  }
 protected void setTracker(Tool newTracker) {
   if (tracker != null) {
     tracker.deactivate(getEditor());
     tracker.removeToolListener(this);
   }
   tracker = newTracker;
   if (tracker != null) {
     tracker.activate(getEditor());
     tracker.addToolListener(this);
   }
 }
 private void updatePosAndSize() {
   if (f_parent != null) {
     Point _tlPos =
         new Point(
             f_parent.getPos().x - f_parent.getSize().width / 2,
             f_parent.getPos().y + f_parent.getSize().height / 2 - AREA_HEIGHT);
     _tlPos.x += ((getNumber() + 0.5) * BUTTON_WIDTH) + (getNumber() + 1) * DIST_X;
     _tlPos.y += AREA_HEIGHT / 2;
     setPos(_tlPos);
     setSize(BUTTON_WIDTH, AREA_HEIGHT - 2 * DIST_Y);
   }
 }
Example #28
0
  /**
   * Searches for the tool with the given name.
   *
   * @param aToolName the name of the tool to search for, cannot be <code>null</code>.
   * @return the tool with the given name, can be <code>null</code> if no such tool can be found.
   */
  private Tool findToolByName(final String aToolName) {
    Tool tool = null;

    final Collection<Tool> tools = getTools();
    for (Tool _tool : tools) {
      if (aToolName.equals(_tool.getName())) {
        tool = _tool;
        break;
      }
    }
    return tool;
  }
 /** @return <code>true</code> if task has been started successfully */
 static boolean runTool(
     String actionId,
     DataContext context,
     @Nullable AnActionEvent e,
     long executionId,
     @Nullable ProcessListener processListener) {
   Tool tool = findTool(actionId, context);
   if (tool != null) {
     return tool.execute(e, new HackyDataContext(context, e), executionId, processListener);
   }
   return false;
 }
Example #30
0
  public RptTitle(Context context, String title) {
    super(context);
    this.setTextColor(Tool.getTextColor(context));
    this.setText(title);

    this.setTextSize(15);
    this.setPadding(Tool.dip2px(getContext(), 10), 1, Tool.dip2px(getContext(), 15), 1);
    this.setGravity(Gravity.CENTER_VERTICAL);

    this.setLayoutParams(getCurLayoutParams());
    this.setBackgroundResource(R.drawable.tabletop);
  }