/** Creates the GUI in a new thread. */
  @Override
  public void run() {
    setContentPane(jDesktopPane);

    // Show parent frame
    setVisible(true);

    // Create menubar
    setJMenuBar(createMenuBar());

    // Create toolsettings as an internal frame.
    toolSettings = new ActiveToolSettings();
    desktopSize = jDesktopPane.getSize();
    internalFrameSize = toolSettings.getSize();
    toolSettings.setLocation((screenSize.width - internalFrameSize.width) / 2, 0);
    jDesktopPane.add(toolSettings, JLayeredPane.PALETTE_LAYER);
    toolSettings.setVisible(true);

    // Create toolbox as an internal frame.
    toolbox = new Toolbox(toolSettings);
    toolbox.setLocation(0, 0);
    jDesktopPane.add(toolbox, JLayeredPane.PALETTE_LAYER);
    toolbox.setVisible(true);

    // Create panel with primary and secondary color
    activeColorSettings = new ActiveColorSettings(jDesktopPane);
    activeColorSettings.setLocation(82, 0);
    jDesktopPane.add(activeColorSettings, JLayeredPane.PALETTE_LAYER);
    activeColorSettings.setVisible(true);
  }
  private Toolbox loadToolbox() throws IOException, URISyntaxException {

    Path foundPath = findToolsDir();

    Toolbox box;
    if (Files.isDirectory(foundPath)) {
      box = new Toolbox(foundPath);

      Path tempDir = Files.createTempDirectory(TOOLS_DIR_NAME);
      Path tempZipFile = tempDir.resolve(TOOLS_ZIP_NAME);

      dirToZip(foundPath, tempZipFile);
      byte[] zipContents = Files.readAllBytes(tempZipFile);
      box.setZipContents(zipContents);
      Files.delete(tempZipFile);
      Files.delete(tempDir);
    }

    // found tools zip
    else {
      FileSystem fs = FileSystems.newFileSystem(foundPath, null);
      Path toolsPath = fs.getPath(TOOLS_DIR_NAME);
      box = new Toolbox(toolsPath);

      byte[] zipContents = Files.readAllBytes(foundPath);
      box.setZipContents(zipContents);
    }

    return box;
  }
 private void hideKeyboard(View view) {
   Toolbox.hideKeyboard(this, view);
 }
  private void export(String defaultText) {
    if (cart.size() == 0) {
      showToast("Add items to your cart first!");
      return;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Save as...");

    final EditText text = new EditText(this);
    text.setText(defaultText);
    builder.setView(text);

    builder.setPositiveButton(
        R.string.save,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            String filename = text.getText().toString();
            if (filename.equals("")) {
              showToast("Please enter a filename");
              export("");
              return;
            }

            if (filename.contains(" ") || filename.contains(".")) {
              showToast("Spaces and periods are not allowed");
              export(filename.replaceAll("[\\. ]", "_"));
              return;
            }

            // to ensure that all character dependencies are met
            List<LessonCharacter> dependencies = new ArrayList<LessonCharacter>();

            Collections.sort(cart);
            String xml = "<ttw name=\"" + filename + "\">\n";
            for (LessonItem item : cart) {
              if (item == allChars) {
                List<String> ids = Toolbox.dba.getAllCharIds();
                source = new ArrayList<LessonItem>(ids.size());
                for (String id : ids) {
                  LessonCharacter character = Toolbox.dba.getCharacterById(id);
                  if (!cart.contains(character) && !dependencies.contains(character)) {
                    dependencies.add(character);
                  }
                }
                continue;
              }

              xml += item.toXml();

              // if it's a lesson, we need to make sure dependencies are met
              if (item instanceof Lesson) {
                Lesson lesson = (Lesson) item;
                List<LessonItem> words = lesson.getWords();
                for (LessonItem word : words) {
                  List<LessonCharacter> characters = ((LessonWord) word).getCharacters();
                  for (LessonCharacter character : characters) {
                    if (!cart.contains(character) && !dependencies.contains(character)) {
                      dependencies.add(character);
                    }
                  }
                }
              }
            }

            // write out contents so far - all lessons
            writeStringToFile(xml, filename, /*append*/ false);
            xml = "";

            int counter = 1;
            for (LessonCharacter character : dependencies) {
              xml += character.toXml();

              // optimization:  write out contents after every 50 characters
              // to avoid out of memory crash that happens somewhere north of 500 characters
              if ((counter % 50) == 0) {
                writeStringToFile(xml, filename, /*append*/ true);
                xml = "";
              }
              counter++;
            }

            xml += "</ttw>\n";
            writeStringToFile(xml, filename, /*append*/ true);
          }
        });

    builder.setNegativeButton(
        R.string.cancel,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            showToast("Not saved");
          }
        });

    AlertDialog dialog = builder.create();

    Toolbox.showKeyboard(dialog);
    dialog.show();
  }
  /** Displays the filter popup and contains the code to filter */
  public void showFilterPopup() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Apply Filter");

    final EditText filterText = new EditText(this);
    builder.setView(filterText);

    builder.setPositiveButton(
        R.string.apply,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            String search = filterText.getText().toString();
            if (search.equals("")) {
              hideKeyboard(filterText);
              return;
            }

            // Filter action: keep matching items from display list
            List<LessonItem> newList = new ArrayList<LessonItem>();
            switch (type) {
              case CHARACTER:
              case WORD:
                topLoop:
                for (LessonItem item : display) {
                  List<String> tags = item.getTags();
                  for (String tag : tags) {
                    if (Toolbox.containsMatch(2, tag, search)) {
                      newList.add(item);
                      continue topLoop;
                    }
                  }
                  Collection<String> values = item.getKeyValues().values();
                  for (String value : values) {
                    if (Toolbox.containsMatch(2, value, search)) {
                      newList.add(item);
                      continue topLoop;
                    }
                  }
                }
                break;
              case LESSON:
                for (LessonItem item : display) {
                  String name = ((Lesson) item).getLessonName();
                  if (Toolbox.containsMatch(2, name, search)) {
                    newList.add(item);
                  }
                }
                break;
            }
            display = newList;
            adapter = new ShoppingCartListAdapter(ShoppingCartActivity.this, display, vi);
            list.setAdapter(adapter);

            // Set state to filtered
            filterButton.setText(R.string.clear_filter);
            filtered = true;
            filterStatus.setText("Filter: " + search);
            hideKeyboard(filterText);
          }
        });
    builder.setNegativeButton(
        R.string.cancel,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            hideKeyboard(filterText);
          }
        });

    AlertDialog dialog = builder.create();

    Toolbox.showKeyboard(dialog);
    dialog.show();
  }
 OJClass getType() {
   String type_name = definition.getTypeSpecifier().toString();
   return Toolbox.forNameAnyway(env, type_name);
 }
Exemple #7
0
  public ToolbarPanel(Toolbox tbox) {
    setRollover(true);

    toolbox = tbox;
    optionPanel = new JPanel(new CardLayout());

    final OptionPanel pointerGroupOptionPanel = createPointerPanel();
    final JToggleButton pointerGroupButton =
        createButton(
            "net/rptools/maptool/client/image/tool/pointer-blue.png",
            "net/rptools/maptool/client/image/tool/pointer-blue-off.png",
            pointerGroupOptionPanel,
            I18N.getText("tools.interaction.tooltip"));

    pointerGroupButton.setSelected(true);
    pointerGroupOptionPanel.activate();

    final JSeparator vertSplit = new JSeparator(JSeparator.VERTICAL);
    final Component vertSpacer = Box.createHorizontalStrut(10);

    final JSeparator horizontalSplit = new JSeparator(JSeparator.HORIZONTAL);
    horizontalSplit.setVisible(false);
    final Component horizontalSpacer = Box.createVerticalStrut(10);
    horizontalSpacer.setVisible(false);

    add(pointerGroupButton);
    add(
        createButton(
            "net/rptools/maptool/client/image/tool/draw-blue.png",
            "net/rptools/maptool/client/image/tool/draw-blue-off.png",
            createDrawPanel(),
            I18N.getText("tools.drawing.tooltip")));
    add(
        createButton(
            "net/rptools/maptool/client/image/tool/temp-blue.png",
            "net/rptools/maptool/client/image/tool/temp-blue-off.png",
            createTemplatePanel(),
            I18N.getText("tools.template.tooltip")));
    add(
        createButton(
            "net/rptools/maptool/client/image/tool/fog-blue.png",
            "net/rptools/maptool/client/image/tool/fog-blue-off.png",
            createFogPanel(),
            I18N.getText("tools.fog.tooltip")));
    add(
        createButton(
            "net/rptools/maptool/client/image/tool/eye-blue.png",
            "net/rptools/maptool/client/image/tool/eye-blue-off.png",
            createTopologyPanel(),
            I18N.getText("tools.topo.tooltip")));
    add(vertSplit);
    add(horizontalSplit);
    add(vertSpacer);
    add(horizontalSpacer);
    add(optionPanel);
    add(Box.createGlue());
    add(createZoneSelectionButton());

    // Non visible tools
    tbox.createTool(GridTool.class);
    tbox.createTool(BoardTool.class);
    tbox.createTool(FacingTool.class);
    tbox.createTool(StampTool.class);

    addPropertyChangeListener(
        "orientation",
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            int orientation = (Integer) evt.getNewValue();

            horizontalSplit.setVisible(orientation == JToolBar.VERTICAL);
            horizontalSpacer.setVisible(orientation == JToolBar.VERTICAL);

            vertSplit.setVisible(orientation == JToolBar.HORIZONTAL);
            vertSpacer.setVisible(orientation == JToolBar.HORIZONTAL);
          }
        });
  }