public static void main(String... aArguments) {
    TextTransfer textTransfer = new TextTransfer();

    // display what is currently on the clipboard
    System.out.println("Clipboard contains:" + textTransfer.getClipboardContents());

    // change the contents and then re-display
    textTransfer.setClipboardContents("blah, blah, blah");
    System.out.println("Clipboard contains:" + textTransfer.getClipboardContents());
  }
Exemple #2
0
  /**
   * Process the menu events.
   *
   * @param evt the event.
   * @param fff the frame in which the menu is present.
   */
  public void processMenuActions(ActionEvent evt, FidoFrame fff) {
    ExportTools et = fff.getExportTools();
    PrintTools pt = fff.getPrintTools();
    CircuitPanel cc = fff.cc;
    String arg = evt.getActionCommand();
    EditorActions edt = cc.getEditorActions();
    CopyPasteActions cpa = cc.getCopyPasteActions();
    ElementsEdtActions eea = cc.getContinuosMoveActions();
    SelectionActions sa = cc.getSelectionActions();
    ParserActions pa = cc.getParserActions();

    // Edit the FidoCadJ code of the drawing
    if (arg.equals(Globals.messages.getString("Define"))) {
      EnterCircuitFrame circuitDialog =
          new EnterCircuitFrame(fff, cc.getParserActions().getText(!cc.extStrict).toString());
      circuitDialog.setVisible(true);

      pa.parseString(new StringBuffer(circuitDialog.getStringCircuit()));
      cc.getUndoActions().saveUndoState();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("LibraryUpdate"))) {
      // Update libraries
      fff.loadLibraries();
      fff.show();
    } else if (arg.equals(Globals.messages.getString("Circ_opt"))) {
      // Options for the current drawing
      fff.showPrefs();
    } else if (arg.equals(Globals.messages.getString("Layer_opt"))) {
      // Options for the layers
      DialogLayer layerDialog = new DialogLayer(fff, cc.dmp.getLayers());
      layerDialog.setVisible(true);

      // It is important that we force a complete recalculation of
      // all details in the drawing, otherwise the buffered setup
      // will not be responsive to the changes in the layer editing.

      cc.dmp.setChanged(true);
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Print"))) {
      // Print the current drawing
      pt.associateToCircuitPanel(cc);
      pt.printDrawing(fff);
    } else if (arg.equals(Globals.messages.getString("SaveName"))) {
      // Save with name
      fff.getFileTools().saveWithName(false);
    } else if (arg.equals(Globals.messages.getString("Save_split"))) {
      // Save with name, split non standard macros
      fff.getFileTools().saveWithName(true);
    } else if (arg.equals(Globals.messages.getString("Save"))) {
      // Save with the current name (if available)
      fff.getFileTools().save(false);
    } else if (arg.equals(Globals.messages.getString("New"))) {
      // New drawing
      fff.createNewInstance();
    } else if (arg.equals(Globals.messages.getString("Undo"))) {
      // Undo the last action
      cc.getUndoActions().undo();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Redo"))) {
      // Redo the last action
      cc.getUndoActions().redo();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("About_menu"))) {
      // Show the about menu
      DialogAbout d = new DialogAbout(fff);
      d.setVisible(true);
    } else if (arg.equals(Globals.messages.getString("Open"))) {
      // Open a file
      OpenFile openf = new OpenFile();
      openf.setParam(fff);
      SwingUtilities.invokeLater(openf);
      /*
          The following code would require a thread safe implementation
          of some of the inner classes (such as CircuitModel), which was
          indeed not the case... Now, yes!
      */
      /*Thread thread = new Thread(openf);
      thread.setDaemon(true);
      // Start the thread
      thread.start();*/

    } else if (arg.equals(Globals.messages.getString("Export"))) {
      // Export the current drawing
      et.launchExport(fff, cc, fff.getFileTools().openFileDirectory);
    } else if (arg.equals(Globals.messages.getString("SelectAll"))) {
      // Select all elements in the current drawing
      sa.setSelectionAll(true);
      // Even if the drawing is not changed, a repaint operation is
      // needed since all selected elements are rendered in green.
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Copy"))) {
      // Copy all selected elements in the clipboard
      cpa.copySelected(!cc.extStrict, false);
    } else if (arg.equals(Globals.messages.getString("Copy_split"))) {
      // Copy elements, splitting non standard macros
      cpa.copySelected(!cc.extStrict, true);
    } else if (arg.equals(Globals.messages.getString("Cut"))) {
      // Cut all the selected elements
      cpa.copySelected(!cc.extStrict, false);
      edt.deleteAllSelected(true);
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Mirror_E"))) {
      // Mirror all the selected elements
      if (eea.isEnteringMacro()) eea.mirrorMacro();
      else edt.mirrorAllSelected();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Rotate"))) {
      // 90 degrees rotation of all selected elements
      if (eea.isEnteringMacro()) eea.rotateMacro();
      else edt.rotateAllSelected();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Duplicate"))) {
      // Duplicate
      cpa.copySelected(!cc.extStrict, false);
      cpa.paste(cc.getMapCoordinates().getXGridStep(), cc.getMapCoordinates().getYGridStep());
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("DefineClipboard"))) {
      // Paste as a new circuit
      TextTransfer textTransfer = new TextTransfer();
      FidoFrame popFrame;
      if (cc.getUndoActions().getModified()) {
        popFrame = fff.createNewInstance();
      } else {
        popFrame = fff;
      }
      pa.parseString(new StringBuffer(textTransfer.getClipboardContents()));
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Paste"))) {
      // Paste some graphical elements
      cpa.paste(cc.getMapCoordinates().getXGridStep(), cc.getMapCoordinates().getYGridStep());
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Close"))) {
      // Close the current window
      if (!fff.getFileTools().checkIfToBeSaved()) {
        return;
      }
      fff.setVisible(false);
      cc.getUndoActions().doTheDishes();
      fff.dispose();
      Globals.openWindows.remove(fff);

      --Globals.openWindowsNumber;

      if (Globals.openWindowsNumber < 1) System.exit(0);
    }
  }