Пример #1
0
  //
  // Build installer window
  //
  public static void showInstallerWindow() {
    _installerFrame = new JFrame(Config.getWindowTitle());

    Container cont = _installerFrame.getContentPane();
    cont.setLayout(new BorderLayout());

    // North pane
    Box topPane = new Box(BoxLayout.X_AXIS);
    JLabel title = new JLabel(Config.getWindowHeading());
    Font titleFont = new Font("SansSerif", Font.BOLD, 22);
    title.setFont(titleFont);
    title.setForeground(Color.black);

    // Create Sun logo
    URL urlLogo = Main.class.getResource(Config.getWindowLogo());
    Image img = Toolkit.getDefaultToolkit().getImage(urlLogo);
    MediaTracker md = new MediaTracker(_installerFrame);
    md.addImage(img, 0);
    try {
      md.waitForAll();
    } catch (Exception ioe) {
      Config.trace(ioe.toString());
    }
    if (md.isErrorID(0)) Config.trace("Error loading image");
    Icon sunLogo = new ImageIcon(img);
    JLabel logoLabel = new JLabel(sunLogo);
    logoLabel.setOpaque(true);
    topPane.add(topPane.createHorizontalStrut(5));
    topPane.add(title);
    topPane.add(topPane.createHorizontalGlue());
    topPane.add(logoLabel);
    topPane.add(topPane.createHorizontalStrut(5));

    // West Pane
    Box westPane = new Box(BoxLayout.X_AXIS);
    westPane.add(westPane.createHorizontalStrut(10));

    // South Pane
    Box bottomPane = new Box(BoxLayout.X_AXIS);
    bottomPane.add(bottomPane.createHorizontalGlue());
    JButton abortButton = new JButton(Config.getWindowAbortButton());
    abortButton.setMnemonic(Config.getWindowAbortMnemonic());
    bottomPane.add(abortButton);
    bottomPane.add(bottomPane.createHorizontalGlue());
    bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));

    // Center Pane
    Box centerPane = new Box(BoxLayout.Y_AXIS);
    JLabel hidden = new JLabel(Config.getWindowHiddenLabel());
    hidden.setVisible(false);
    centerPane.add(hidden);
    _stepLabels = new JLabel[5];
    for (int i = 0; i < _stepLabels.length; i++) {
      _stepLabels[i] = new JLabel(Config.getWindowStep(i));
      _stepLabels[i].setEnabled(false);
      centerPane.add(_stepLabels[i]);

      // install label's length will expand,so set a longer size.
      if (i == STEP_INSTALL) {
        Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize();
        _stepLabels[i].setPreferredSize(dim);
      }
    }
    hidden = new JLabel(Config.getWindowHiddenLabel());
    hidden.setVisible(false);
    centerPane.add(hidden);

    // Setup box layout
    cont.add(topPane, "North");
    cont.add(westPane, "West");
    cont.add(bottomPane, "South");
    cont.add(centerPane, "Center");

    _installerFrame.pack();
    Dimension dim = _installerFrame.getSize();

    // hard code to ensure title is completely visible on Sol/lin.
    if (dim.width < 400) {
      dim.width = 400;
      _installerFrame.setSize(dim);
    }

    Rectangle size = _installerFrame.getBounds();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    size.width = Math.min(screenSize.width, size.width);
    size.height = Math.min(screenSize.height, size.height);
    // Put window at 1/4, 1/4 of screen resoluion
    _installerFrame.setBounds(
        (screenSize.width - size.width) / 4,
        (screenSize.height - size.height) / 4,
        size.width,
        size.height);

    // Setup event listners
    _installerFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent we) {
            installFailed("Window closed", null);
          }
        });

    abortButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            installFailed("Abort pressed", null);
          }
        });

    // Show window
    _installerFrame.show();
  }
Пример #2
0
/**
 * The Processing Plugin. Refer to Processing.__applet to get at the __applet.
 *
 * <p>E.g. var P = Java.type('fieldprocessing.Processing').__applet
 *
 * <p>This adds a command "Bridge box to Processing". Run that to move this box (and any children)
 * into the Processing draw cycle. Then you can write things like:
 *
 * <p>P.background(0) // sets background to black
 */
public class Processing extends Execution {

  public static final Dict.Prop<FieldProcessingAppletDelgate> P =
      new Dict.Prop<FieldProcessingAppletDelgate>("P")
          .toCannon()
          .type()
          .doc("the Processing Applet. e.g. `_.P.background(0)` sets the background to black.");

  private ProcessingExecution processingExecution;
  public FieldProcessingApplet __applet;
  public static FieldProcessingAppletDelgate applet;

  private List<Runnable> queue = new ArrayList<>();

  protected JFrame frame;

  int sizeX =
      AutoPersist.persist(
          "processing_sizeX",
          () -> 400,
          x -> Math.min(2560, Math.max(100, x)),
          (x) -> frame.getSize().width);
  int sizeY =
      AutoPersist.persist(
          "processing_sizeY",
          () -> 400,
          x -> Math.min(2560, Math.max(100, x)),
          (x) -> frame.getSize().height);

  public interface MouseHandler {
    public void handle(FieldProcessingApplet applet, Object /*MouseEvent or MouseMoveEvent*/ event);
  }

  public interface KeyHandler {
    public void handle(FieldProcessingApplet applet, processing.event.KeyEvent event);
  }

  public Processing(Box root) {
    super(null);

    Log.log("startup.processing", " processing plugin is starting up ");

    frame = new JFrame("Field/Processing");
    __applet =
        new FieldProcessingApplet(
            sizeX,
            sizeY,
            queue,
            this,
            s -> {
              if (getLastErrorOutput() != null) getLastErrorOutput().accept(new Pair<>(-1, s));
            });

    __applet.init();
    __applet.loop();
    frame.add(__applet, BorderLayout.CENTER);
    frame.setSize(sizeX, sizeY);
    frame.setVisible(true);
    frame.validate();

    applet = new FieldProcessingAppletDelgate(__applet);

    this.properties.put(P, applet);

    Log.log("startup.processing", " searching for boxes that need processing support ");

    Log.log("startup.processing", " processing plugin has finished starting up ");
  }

  private Stream<Box> selection() {
    return breadthFirst(both()).filter(x -> x.properties.isTrue(Mouse.isSelected, false));
  }

  public Execution.ExecutionSupport support(Box box, Dict.Prop<String> prop) {
    FunctionOfBox<Boolean> ef = this.properties.get(executionFilter);
    if (box == this || ef == null || ef.apply(box)) return wrap(box, prop);
    return null;
  }

  public Consumer<Pair<Integer, String>> lastErrorOutput;

  public Consumer<Pair<Integer, String>> getLastErrorOutput() {
    return lastErrorOutput;
  }

  private Execution.ExecutionSupport wrap(Box box, Dict.Prop<String> prop) {

    return new Execution.ExecutionSupport() {

      @Override
      public void executeTextFragment(
          String textFragment,
          String suffix,
          Consumer<String> success,
          Consumer<Pair<Integer, String>> lineErrors) {
        System.out.println(" WRAPPED :" + textFragment);
        queue.add(
            () -> {
              Execution delegateTo =
                  box.find(Execution.execution, box.upwards())
                      .findFirst()
                      .orElseThrow(
                          () ->
                              new IllegalArgumentException(
                                  " can't instantiate Processing execution - no default execution found"));
              Execution.ExecutionSupport s = delegateTo.support(box, prop);

              s.executeTextFragment(textFragment, "", success, lineErrors);
            });
      }

      @Override
      public Object getBinding(String name) {
        Execution delegateTo =
            box.find(Execution.execution, box.upwards())
                .findFirst()
                .orElseThrow(
                    () ->
                        new IllegalArgumentException(
                            " can't instantiate Processing execution - no default execution found"));
        Execution.ExecutionSupport s = delegateTo.support(box, prop);
        return s.getBinding(name);
      }

      @Override
      public void executeAll(
          String allText, Consumer<Pair<Integer, String>> lineErrors, Consumer<String> success) {
        System.out.println(" WRAPPED :" + allText);
        queue.add(
            () -> {
              Execution delegateTo =
                  box.find(Execution.execution, box.upwards())
                      .findFirst()
                      .orElseThrow(
                          () ->
                              new IllegalArgumentException(
                                  " can't instantiate Processing execution - no default execution found"));
              Execution.ExecutionSupport s = delegateTo.support(box, prop);
              s.executeAll(allText, lineErrors, success);
            });
      }

      @Override
      public String begin(
          Consumer<Pair<Integer, String>> lineErrors,
          Consumer<String> success,
          Map<String, Object> initiator) {

        lastErrorOutput = lineErrors;
        Execution delegateTo =
            box.find(Execution.execution, box.upwards())
                .findFirst()
                .orElseThrow(
                    () ->
                        new IllegalArgumentException(
                            " can't instantiate Processing execution - no default execution found"));
        Execution.ExecutionSupport s = delegateTo.support(box, prop);

        String name = s.begin(lineErrors, success, initiator);
        if (name == null) return null;
        Supplier<Boolean> was = box.properties.removeFromMap(Boxes.insideRunLoop, name);
        String newName = name.replace("main.", "processing.");
        box.properties.putToMap(Boxes.insideRunLoop, newName, was);
        box.first(IsExecuting.isExecuting).ifPresent(x -> x.accept(box, newName));

        return name;
      }

      @Override
      public void end(Consumer<Pair<Integer, String>> lineErrors, Consumer<String> success) {
        System.out.println(" WRAPPED (end)");
        Execution delegateTo =
            box.find(Execution.execution, box.upwards())
                .filter(x -> x != Processing.this)
                .findFirst()
                .orElseThrow(
                    () ->
                        new IllegalArgumentException(
                            " can't instantiate Processing execution - no default execution found"));
        Execution.ExecutionSupport s = delegateTo.support(box, prop);
        s.end(lineErrors, success);
      }

      @Override
      public void setConsoleOutput(Consumer<String> stdout, Consumer<String> stderr) {
        System.out.println(" WRAPPED (stdout)");
        Execution delegateTo =
            box.find(Execution.execution, box.upwards())
                .filter(x -> x != Processing.this)
                .findFirst()
                .orElseThrow(
                    () ->
                        new IllegalArgumentException(
                            " can't instantiate Processing execution - no default execution found"));
        Execution.ExecutionSupport s = delegateTo.support(box, prop);
        s.setConsoleOutput(stdout, stderr);
      }

      @Override
      public void completion(String allText, int line, int ch, Consumer<List<Completion>> results) {
        System.out.println(" WRAPPED (completion) " + allText);
        Execution delegateTo =
            box.find(Execution.execution, box.upwards())
                .filter(x -> x != Processing.this)
                .findFirst()
                .orElseThrow(
                    () ->
                        new IllegalArgumentException(
                            " can't instantiate Processing execution - no default execution found"));
        Execution.ExecutionSupport s = delegateTo.support(box, prop);
        s.completion(allText, line, ch, results);
      }

      @Override
      public void imports(String allText, int line, int ch, Consumer<List<Completion>> results) {
        System.out.println(" WRAPPED (imports) " + allText);
        Execution delegateTo =
            box.find(Execution.execution, box.upwards())
                .filter(x -> x != Processing.this)
                .findFirst()
                .orElseThrow(
                    () ->
                        new IllegalArgumentException(
                            " can't instantiate Processing execution - no default execution found"));
        Execution.ExecutionSupport s = delegateTo.support(box, prop);
        s.imports(allText, line, ch, results);
      }

      @Override
      public String getCodeMirrorLanguageName() {
        Execution delegateTo =
            box.find(Execution.execution, box.upwards())
                .filter(x -> x != Processing.this)
                .findFirst()
                .orElseThrow(
                    () ->
                        new IllegalArgumentException(
                            " can't instantiate Processing execution - no default execution found"));
        Execution.ExecutionSupport s = delegateTo.support(box, prop);
        return s.getCodeMirrorLanguageName();
      }

      @Override
      public String getDefaultFileExtension() {
        Execution delegateTo =
            box.find(Execution.execution, box.upwards())
                .filter(x -> x != Processing.this)
                .findFirst()
                .orElseThrow(
                    () ->
                        new IllegalArgumentException(
                            " can't instantiate Processing execution - no default execution found"));
        Execution.ExecutionSupport s = delegateTo.support(box, prop);
        return s.getDefaultFileExtension();
      }
    };
  }
}
  void main() {

    CommonSwing.setDefaultColor();

    fMain = new JFrame("HSQL Database Manager");

    // (ulrivo): An actual icon.
    fMain.getContentPane().add(createToolBar(), "North");
    fMain.setIconImage(CommonSwing.getIcon());
    fMain.addWindowListener(this);

    JMenuBar bar = new JMenuBar();

    // used shortcuts: CERGTSIUDOLM
    String fitems[] = {
      "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "--", "-Exit"
    };

    addMenu(bar, "File", fitems);

    String vitems[] = {"RRefresh Tree", "--", "GResults in Grid", "TResults in Text"};

    addMenu(bar, "View", vitems);

    String sitems[] = {
      "SSELECT",
      "IINSERT",
      "UUPDATE",
      "DDELETE",
      "---",
      "-CREATE TABLE",
      "-DROP TABLE",
      "-CREATE INDEX",
      "-DROP INDEX",
      "--",
      "-CHECKPOINT",
      "-SCRIPT",
      "-SET",
      "-SHUTDOWN",
      "--",
      "-Test Script"
    };

    addMenu(bar, "Command", sitems);

    mRecent = new JMenu("Recent");

    bar.add(mRecent);

    String soptions[] = {
      "-AutoCommit on",
      "-AutoCommit off",
      "OCommit",
      "LRollback",
      "--",
      "-Disable MaxRows",
      "-Set MaxRows to 100",
      "--",
      "-Logging on",
      "-Logging off",
      "--",
      "-Insert test data"
    };

    addMenu(bar, "Options", soptions);

    String stools[] = {"-Dump", "-Restore", "-Transfer"};

    addMenu(bar, "Tools", stools);
    fMain.setJMenuBar(bar);
    initGUI();

    sRecent = new String[iMaxRecent];

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = fMain.getSize();

    // (ulrivo): full size on screen with less than 640 width
    if (d.width >= 640) {
      fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
    } else {
      fMain.setLocation(0, 0);
      fMain.setSize(d);
    }

    fMain.show();

    // (ulrivo): load query from command line
    if (defScript != null) {
      if (defDirectory != null) {
        defScript = defDirectory + File.separator + defScript;
      }

      // if insert stmet is thousands of records...skip showing it
      // as text.  Too huge.
      StringBuffer buf = new StringBuffer();

      ifHuge = DatabaseManagerCommon.readFile(defScript);

      if (4096 <= ifHuge.length()) {
        buf.append("This huge file cannot be edited. Please execute\n");
        txtCommand.setText(buf.toString());
      } else {
        txtCommand.setText(ifHuge);
      }
    }

    txtCommand.requestFocus();
  }