Esempio n. 1
0
 // Makes sure the log is visible.
 private static void displayLog() {
   if (!consoleDisplayed) {
     splitter.add(outputScroll);
     splitter.setDividerLocation(defaultSliderPosition);
     consoleDisplayed = true;
   }
 }
 // Makes sure the log is visible.
 private static void displayLog() {
   println("Displayed", warning);
   if (!consoleDisplayed) {
     splitter.add(outputScroll);
     splitter.setDividerLocation(.8);
     consoleDisplayed = true;
   }
 }
    public void actionPerformed(ActionEvent a) {
      String command = a.getActionCommand();
      if (command.equals("e")) {
        // Log toggle.
        if (consoleDisplayed = !consoleDisplayed) {
          splitter.add(outputScroll);
          splitter.setDividerLocation(.8);
        } else {
          splitter.remove(outputScroll);
        }
      } else if (command.equals("k")) {
        if (text.getText().contains("class")) {
          // This means we should try to compile this as normal.

          // Pulls out class name
          String code = text.getText();
          int firstPos = code.indexOf("class");
          int secondPos = code.indexOf("{");
          String name = code.substring(firstPos + "class".length() + 1, secondPos).trim();

          compileAndRun(name, text.getText());
        } else {
          // This means we should compile this as a playground.
          String code = text.getText();

          // Common import statements built-in
          String importDump = new String();
          importDump +=
              ("import java.util.*;\n"
                  + "import javax.swing.*;\n"
                  + "import javax.swing.event.*;\n"
                  + "import java.awt.*;\n"
                  + "import java.awt.event.*;\n"
                  + "import java.io.*;\n");

          // Pulls out any "import" statements and appends them to the import dump.
          int i = code.indexOf("import");
          while (i >= 0) {
            String s = code.substring(i, code.indexOf(";", i) + 1);
            code = code.replaceFirst(s, "");
            importDump += s + "\n";
            i = code.indexOf("import", i + 1);
          }

          // Inject the class header and main method
          code =
              "//User and auto-imports pre-defined\n"
                  + importDump
                  + "//Autogenerated class\npublic class Main {\npublic static void main(String[] args) {\n"
                  + code
                  + "\n}\n}";

          compileAndRun("Main", code);
        }
      }
    }
Esempio n. 4
0
 public FigurePanel() {
   setLayout(new BorderLayout());
   JPanel panel = new JPanel();
   panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
   panel.add(fs);
   panel.add(bp);
   JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel, cp);
   sp.setPreferredSize(new Dimension(500, 400));
   sp.setDividerLocation(250);
   add(BorderLayout.CENTER, sp);
 }
Esempio n. 5
0
    void show() {
      if (isShowing) return;

      tablePanel.remove(currentComponent);
      split.setLeftComponent(currentComponent);
      split.setDividerLocation(splitPos);
      currentComponent = split;
      tablePanel.add(currentComponent, BorderLayout.CENTER);
      tablePanel.revalidate();
      isShowing = true;
    }
Esempio n. 6
0
  public DatasetViewer(PreferencesExt prefs, FileManager fileChooser) {
    this.prefs = prefs;
    this.fileChooser = fileChooser;

    // create the variable table(s)
    tablePanel = new JPanel(new BorderLayout());
    setNestedTable(0, null);

    // the tree view
    datasetTree = new DatasetTreeView();
    datasetTree.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent e) {
            setSelected((Variable) e.getNewValue());
          }
        });

    // layout
    mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, datasetTree, tablePanel);
    mainSplit.setDividerLocation(prefs.getInt("mainSplit", 100));

    setLayout(new BorderLayout());
    add(mainSplit, BorderLayout.CENTER);

    // the info window
    infoTA = new TextHistoryPane();
    infoWindow =
        new IndependentWindow("Variable Information", BAMutil.getImage("netcdfUI"), infoTA);
    infoWindow.setBounds(
        (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300)));

    // the data Table
    dataTable = new StructureTable((PreferencesExt) prefs.node("structTable"));
    dataWindow = new IndependentWindow("Data Table", BAMutil.getImage("netcdfUI"), dataTable);
    dataWindow.setBounds(
        (Rectangle) prefs.getBean("dataWindow", new Rectangle(50, 300, 1000, 600)));

    // the ncdump Pane
    dumpPane = new NCdumpPane((PreferencesExt) prefs.node("dumpPane"));
    dumpWindow =
        new IndependentWindow("NCDump Variable Data", BAMutil.getImage("netcdfUI"), dumpPane);
    dumpWindow.setBounds(
        (Rectangle) prefs.getBean("DumpWindowBounds", new Rectangle(300, 300, 300, 200)));
  }
  public BufrMessageViewer(final PreferencesExt prefs, JPanel buttPanel) {
    this.prefs = prefs;

    AbstractAction useReaderAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            Boolean state = (Boolean) getValue(BAMutil.STATE);
            doRead = state.booleanValue();
          }
        };
    BAMutil.setActionProperties(useReaderAction, "addCoords", "read data", true, 'C', -1);
    useReaderAction.putValue(BAMutil.STATE, new Boolean(doRead));
    BAMutil.addActionToContainer(buttPanel, useReaderAction);

    AbstractAction seperateWindowAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            Boolean state = (Boolean) getValue(BAMutil.STATE);
            seperateWindow = state.booleanValue();
          }
        };
    BAMutil.setActionProperties(
        seperateWindowAction, "addCoords", "seperate DDS window", true, 'C', -1);
    seperateWindowAction.putValue(BAMutil.STATE, new Boolean(seperateWindow));
    BAMutil.addActionToContainer(buttPanel, seperateWindowAction);

    messageTable =
        new BeanTableSorted(
            MessageBean.class, (PreferencesExt) prefs.node("GridRecordBean"), false);
    messageTable.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            ddsTable.setBeans(new ArrayList());
            obsTable.setBeans(new ArrayList());

            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            java.util.List<DdsBean> beanList = new ArrayList<DdsBean>();
            try {
              setDataDescriptors(beanList, mb.m.getRootDataDescriptor(), 0);
              setObs(mb.m);
            } catch (IOException e1) {
              JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage());
              e1
                  .printStackTrace(); // To change body of catch statement use File | Settings |
                                      // File Templates.
            }
            ddsTable.setBeans(beanList);
          }
        });

    obsTable = new BeanTableSorted(ObsBean.class, (PreferencesExt) prefs.node("ObsBean"), false);
    obsTable.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            ObsBean csb = (ObsBean) obsTable.getSelectedBean();
          }
        });

    ddsTable = new BeanTableSorted(DdsBean.class, (PreferencesExt) prefs.node("DdsBean"), false);
    ddsTable.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            DdsBean csb = (DdsBean) ddsTable.getSelectedBean();
          }
        });

    thredds.ui.PopupMenu varPopup = new thredds.ui.PopupMenu(messageTable.getJTable(), "Options");
    varPopup.addAction(
        "Show DDS",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean vb = (MessageBean) messageTable.getSelectedBean();
            if (!seperateWindow) infoTA.clear();
            Formatter f = new Formatter();
            try {
              if (!vb.m.isTablesComplete()) {
                f.format(" MISSING DATA DESCRIPTORS= ");
                vb.m.showMissingFields(f);
                f.format("%n%n");
              }

              vb.m.dump(f);
            } catch (IOException e1) {
              JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage());
              e1
                  .printStackTrace(); // To change body of catch statement use File | Settings |
                                      // File Templates.
            }
            if (seperateWindow) {
              TextHistoryPane ta = new TextHistoryPane();
              IndependentWindow info =
                  new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), ta);
              info.setBounds(
                  (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300)));
              ta.appendLine(f.toString());
              ta.gotoTop();
              info.show();

            } else {
              infoTA.appendLine(f.toString());
              infoTA.gotoTop();
              infoWindow.show();
            }
          }
        });
    varPopup.addAction(
        "Data Table",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            try {
              NetcdfDataset ncd = getBufrMessageAsDataset(mb.m);
              Variable v = ncd.findVariable(BufrIosp.obsRecord);
              if ((v != null) && (v instanceof Structure)) {
                if (dataTable == null) makeDataTable();
                dataTable.setStructure((Structure) v);
                dataWindow.show();
              }
            } catch (Exception ex) {
              JOptionPane.showMessageDialog(BufrMessageViewer.this, ex.getMessage());
              ex.printStackTrace();
            }
          }
        });

    varPopup.addAction(
        "Bit Count",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            Message m = mb.m;

            Formatter out = new Formatter();
            try {
              infoTA2.clear();
              if (!m.dds.isCompressed()) {
                MessageUncompressedDataReader reader = new MessageUncompressedDataReader();
                reader.readData(null, m, raf, null, false, out);
              } else {
                MessageCompressedDataReader reader = new MessageCompressedDataReader();
                reader.readData(null, m, raf, null, out);
              }
              int nbitsGiven = 8 * (m.dataSection.getDataLength() - 4);
              DataDescriptor root = m.getRootDataDescriptor();
              out.format(
                  "Message nobs=%d compressed=%s vlen=%s countBits= %d givenBits=%d %n",
                  m.getNumberDatasets(),
                  m.dds.isCompressed(),
                  root.isVarLength(),
                  m.getCountedDataBits(),
                  nbitsGiven);
              out.format(" countBits= %d givenBits=%d %n", m.getCountedDataBits(), nbitsGiven);
              out.format(
                  " countBytes= %d dataSize=%d %n",
                  m.getCountedDataBytes(), m.dataSection.getDataLength());
              out.format("%n");
              infoTA2.appendLine(out.toString());

            } catch (Exception ex) {
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              ex.printStackTrace(new PrintStream(bos));
              infoTA2.appendLine(out.toString());
              infoTA2.appendLine(bos.toString());
            }

            infoTA2.gotoTop();
            infoWindow2.show();
          }
        });

    varPopup.addAction(
        "Write Message",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            try {
              String defloc;
              String header = mb.m.getHeader();
              if (header != null) {
                header = header.split(" ")[0];
              }
              if (header == null) {
                defloc = (raf.getLocation() == null) ? "." : raf.getLocation();
                int pos = defloc.lastIndexOf(".");
                if (pos > 0) defloc = defloc.substring(0, pos);
              } else defloc = header;

              if (fileChooser == null)
                fileChooser =
                    new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager"));

              String filename = fileChooser.chooseFilenameToSave(defloc + ".bufr");
              if (filename == null) return;

              File file = new File(filename);
              FileOutputStream fos = new FileOutputStream(file);
              WritableByteChannel wbc = fos.getChannel();
              wbc.write(ByteBuffer.wrap(mb.m.getHeader().getBytes()));

              byte[] raw = scan.getMessageBytes(mb.m);
              wbc.write(ByteBuffer.wrap(raw));
              wbc.close();
              JOptionPane.showMessageDialog(
                  BufrMessageViewer.this, filename + " successfully written");

            } catch (Exception ex) {
              JOptionPane.showMessageDialog(BufrMessageViewer.this, "ERROR: " + ex.getMessage());
              ex.printStackTrace();
            }
          }
        });

    varPopup.addAction(
        "Dump distinct DDS",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            dumpDDS();
          }
        });

    varPopup.addAction(
        "Write all distinct messages",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            writeAll();
          }
        });

    varPopup.addAction(
        "Show XML",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            Message m = mb.m;

            ByteArrayOutputStream out = new ByteArrayOutputStream(1000 * 100);
            try {
              infoTA.clear();

              NetcdfDataset ncd = getBufrMessageAsDataset(mb.m);
              new Bufr2Xml(m, ncd, out, true);
              infoTA.setText(out.toString());

            } catch (Exception ex) {
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              ex.printStackTrace(new PrintStream(bos));
              infoTA.appendLine(out.toString());
              infoTA.appendLine(bos.toString());
            }

            infoTA.gotoTop();
            infoWindow.show();
          }
        });

    // the info window
    infoTA = new TextHistoryPane();
    infoWindow = new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), infoTA);
    infoWindow.setBounds(
        (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300)));

    // the info window 2
    infoTA2 = new TextHistoryPane();
    infoWindow2 =
        new IndependentWindow("Extra Information-2", BAMutil.getImage("netcdfUI"), infoTA2);
    infoWindow2.setBounds(
        (Rectangle) prefs.getBean("InfoWindowBounds2", new Rectangle(300, 300, 500, 300)));

    split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, ddsTable, obsTable);
    split2.setDividerLocation(prefs.getInt("splitPos2", 800));

    split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, messageTable, split2);
    split.setDividerLocation(prefs.getInt("splitPos", 500));

    setLayout(new BorderLayout());
    add(split, BorderLayout.CENTER);
  }
Esempio n. 8
0
  void jbInit() throws Exception {
    titledBorder1 =
        new TitledBorder(
            BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "Assembler messages");
    this.getContentPane().setLayout(borderLayout1);

    this.setIconifiable(true);
    this.setMaximizable(true);
    this.setResizable(true);

    this.setTitle("EDIT");

    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPane.setDividerLocation(470);
    sourceArea.setFont(new java.awt.Font("Monospaced", 0, 12));
    controlPanel.setLayout(gridBagLayout1);
    controlPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    positionPanel.setLayout(gridBagLayout2);
    fileLabel.setText("Source file:");
    fileText.setEditable(false);
    browseButton.setSelected(false);
    browseButton.setText("Browse ...");
    assembleButton.setEnabled(false);
    assembleButton.setText("Assemble file");
    saveButton.setEnabled(false);
    saveButton.setText("Save file");
    lineLabel.setText("Line:");
    lineText.setMinimumSize(new Dimension(50, 20));
    lineText.setPreferredSize(new Dimension(50, 20));
    lineText.setEditable(false);
    columnLabel.setText("Column:");
    columnText.setMinimumSize(new Dimension(41, 20));
    columnText.setPreferredSize(new Dimension(41, 20));
    columnText.setEditable(false);
    columnText.setText("");
    messageScrollPane.setBorder(titledBorder1);
    messageScrollPane.setMinimumSize(new Dimension(33, 61));
    messageScrollPane.setPreferredSize(new Dimension(60, 90));
    optionsButton.setEnabled(false);
    optionsButton.setText("Assembler options ...");
    messageScrollPane.getViewport().add(messageList, null);
    messageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.getContentPane().add(splitPane, BorderLayout.CENTER);
    splitPane.add(textScrollPane, JSplitPane.TOP);
    splitPane.add(controlPanel, JSplitPane.BOTTOM);
    textScrollPane.getViewport().add(sourceArea, null);

    controlPanel.add(
        fileLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        fileText,
        new GridBagConstraints(
            1,
            0,
            3,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        browseButton,
        new GridBagConstraints(
            4,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    controlPanel.add(
        optionsButton,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        assembleButton,
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        saveButton,
        new GridBagConstraints(
            4,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    controlPanel.add(
        positionPanel,
        new GridBagConstraints(
            0,
            1,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    positionPanel.add(
        lineLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
    positionPanel.add(
        lineText,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0),
            0,
            0));
    positionPanel.add(
        columnLabel,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    positionPanel.add(
        columnText,
        new GridBagConstraints(
            3,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        messageScrollPane,
        new GridBagConstraints(
            0,
            2,
            5,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));
  }
Esempio n. 9
0
  public void launchChess() {

    mainWindow = new JFrame("网络黑白棋	作者:张炀");
    jpWest = new JPanel();
    jpEast = new JPanel();
    jpNorth = new JPanel();
    jpSouth = new JPanel();
    jpCenter = new JPanel();

    turnLabel = new JLabel();
    blackNumberLabel = new JLabel("黑棋:\n" + black + "		");
    whiteNumberLabel = new JLabel("白棋:\n" + white + "		");
    timeLabel = new JLabel("时间:  " + time + "		s");
    noticeLabel = new JLabel();

    noticeLabel = new JLabel("请选择:");
    numberPane = new JPanel();
    readyPane = new JPanel();
    jt1 = new JTextField(18); // 发送信息框
    jt2 = new JTextArea(3, 30); // 显示信息框
    js = new JScrollPane(jt2);
    jt2.setLineWrap(true);
    jt2.setEditable(false);
    //		jt1.setLineWrap(true);

    send = new JButton("发送");
    cancel = new JButton("取消");
    regret = new JButton("悔棋");
    submit = new JButton("退出");
    begin = new JButton("开始");
    save = new JButton("存盘");

    save.setEnabled(true);
    begin.setEnabled(true);

    fighter = new JRadioButton("下棋");
    audience = new JRadioButton("观看");
    group = new ButtonGroup();
    group.add(audience);
    group.add(fighter);
    group.add(AIPlayer);

    submit.addActionListener(this);
    begin.addActionListener(this);
    save.addActionListener(this);
    send.addActionListener(this);
    cancel.addActionListener(this);
    regret.addActionListener(this);
    fighter.addActionListener(this);
    audience.addActionListener(this);

    jpNorth.setLayout(new BorderLayout());
    jpNorth.add(turnLabel, BorderLayout.NORTH);
    jpNorth.add(jpCenter, BorderLayout.CENTER);
    jpSouth.add(js);
    jpSouth.add(jt1);
    jpSouth.add(send);
    jpSouth.add(cancel);
    jpEast.setLayout(new GridLayout(3, 1));
    submit.setBackground(new Color(130, 251, 241));
    panel x = new panel();
    jpEast.add(x);
    jpEast.add(numberPane);
    jpEast.add(readyPane);

    numberPane.add(blackNumberLabel);
    numberPane.add(whiteNumberLabel);
    numberPane.add(timeLabel);
    numberPane.add(submit);
    numberPane.add(begin);
    numberPane.add(save);
    numberPane.add(regret);

    readyPane.add(noticeLabel);
    readyPane.add(fighter);
    readyPane.add(audience);
    //		readyPane.add(save);
    //		readyPane.add(regret);

    jpCenter.setSize(400, 400);
    jmb = new JMenuBar();
    document = new JMenu("游戏		");
    edit = new JMenu("设置		");
    insert = new JMenu("棋盘			");
    help = new JMenu("帮助		");
    jmb.add(document);
    jmb.add(edit);
    jmb.add(insert);
    jmb.add(help);
    // mainWindow.setJMenuBar(jmb);

    mainWindow.setBounds(80, 80, 600, 600);
    mainWindow.setResizable(false);

    jsLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, jpNorth, jpSouth);
    jsBase = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, jsLeft, jpEast);

    mainWindow.add(jsBase);
    mainWindow.setVisible(true);
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jsBase.setDividerLocation(0.7);
    jsLeft.setDividerLocation(0.78);

    jpCenter.setLayout(new GridLayout(8, 8, 0, 0));
    ImageIcon key = new ImageIcon("chess1.jpg");
    for (int i = 0; i < cell.length; i++)
      for (int j = 0; j < cell.length; j++) {
        cell[i][j] = new ChessBoard(i, j);
        cell[i][j].addMouseListener(this);
        jpCenter.add(cell[i][j]);
      }

    cell[3][3].state = cell[4][4].state = '黑';
    cell[4][3].state = cell[3][4].state = '白';
    cell[3][3].taken = cell[4][4].taken = true;
    cell[4][3].taken = cell[3][4].taken = true;

    RememberState();

    new Thread(new TurnLabel(this)).start();

    file = new File("D:/" + myRole);
    try {
      fout = new FileOutputStream(file);
      out = new ObjectOutputStream(fout);
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    Connect();

    try {
      out99 = new ObjectOutputStream(socket99.getOutputStream());
      in99 = new ObjectInputStream(socket99.getInputStream());

      out66 = new ObjectOutputStream(socket66.getOutputStream());
      in66 = new ObjectInputStream(socket66.getInputStream());

      out88 = new DataOutputStream(socket88.getOutputStream());
    } catch (IOException e) {
      e.printStackTrace();
    }

    new Thread(new Client9999(this)).start();
    new Thread(new Client6666(this)).start();
  }
Esempio n. 10
0
  public DOMTreeView(Document dom) {
    super("TreeWalkerView ");

    document = dom;
    // jtree  UI setup
    jtree = new DOMTreeFull((Node) document);
    jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Listen for when the selection changes, call nodeSelected(node)
    jtree.addTreeSelectionListener(
        new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent e) {
            TreePath path = (TreePath) e.getPath();
            TreeNode treeNode = (TreeNode) path.getLastPathComponent();
            if (jtree.getSelectionModel().isPathSelected(path)) nodeSelected(treeNode);
          }
        });

    treeScroll = new JScrollPane(jtree);
    treeScroll.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("DOM Tree View"),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));

    JPanel urlPanel = new JPanel();
    JLabel urlLabel = new JLabel("URL:");
    urlTextField = new JTextField(50);
    urlTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == urlTextField) {
              reloadJTree(urlTextField.getText());
            }
          }
        });
    urlPanel.add(urlLabel);
    urlPanel.add(urlTextField);

    JPanel selectedXPathPanel = new JPanel();
    JLabel xpathLabel = new JLabel("XPath: ");
    selectedXPathTextField = new JTextField(50);
    selectedXPathTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == selectedXPathTextField) {
              lookupByXPath(selectedXPathTextField.getText());
            }
          }
        });
    selectedXPathPanel.add(xpathLabel);
    selectedXPathPanel.add(selectedXPathTextField);

    JPanel lookupPanel = new JPanel();
    JLabel lookupLabel = new JLabel("look up:");
    lookupTextField = new JTextField(20);
    lookupTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == lookupTextField) {
              lookup(lookupTextField.getText());
            }
          }
        });
    foundList = new JList();
    foundList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    foundList.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent evt) {
            Object source = evt.getSource();
            if (source == foundList) {
              FoundItem fi = (FoundItem) foundList.getSelectedValue();
              if (fi == null) return;
              jtree.setSelectionPath(fi.treePath);
              jtree.scrollPathToVisible(fi.treePath);
            }
          }
        });

    JScrollPane foundScroll = new JScrollPane(foundList);
    foundScroll.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Nodes found"),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));
    // foundScroll.set
    JPanel queryPanel = new JPanel();
    queryPanel.add(lookupLabel);
    queryPanel.add(lookupTextField);
    lookupPanel.setLayout(new BorderLayout());
    lookupPanel.add(queryPanel, BorderLayout.NORTH);
    lookupPanel.add(foundScroll, BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, lookupPanel);
    splitPane.setContinuousLayout(true);
    splitPane.setOneTouchExpandable(true);

    splitPane.setDividerLocation(400);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.add(urlPanel, BorderLayout.NORTH);
    mainPanel.add(selectedXPathPanel, BorderLayout.SOUTH);
    mainPanel.add(splitPane, BorderLayout.CENTER);
    // mainPanel.add(treeScroll, BorderLayout.CENTER);
    // mainPanel.add(lookupPanel, BorderLayout.EAST);

    getContentPane().add(mainPanel);
  }
Esempio n. 11
0
    NestedTable(int level) {
      this.level = level;
      myPrefs = (PreferencesExt) prefs.node("NestedTable" + level);

      table = new BeanTableSorted(VariableBean.class, myPrefs, false);

      JTable jtable = table.getJTable();
      PopupMenu csPopup = new PopupMenu(jtable, "Options");
      csPopup.addAction(
          "Show Declaration",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showDeclaration(table, false);
            }
          });
      csPopup.addAction(
          "Show NcML",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showDeclaration(table, true);
            }
          });
      csPopup.addAction(
          "NCdump Data",
          "Dump",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              dumpData(table);
            }
          });
      if (level == 0) {
        csPopup.addAction(
            "Data Table",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                dataTable(table);
              }
            });
      }

      // get selected variable, see if its a structure
      table.addListSelectionListener(
          new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
              Variable v = getCurrentVariable(table);
              if ((v != null) && (v instanceof Structure)) {
                hideNestedTable(NestedTable.this.level + 2);
                setNestedTable(NestedTable.this.level + 1, (Structure) v);

              } else {
                hideNestedTable(NestedTable.this.level + 1);
              }
              if (eventsOK) datasetTree.setSelected(v);
            }
          });

      // layout
      if (currentComponent == null) {
        currentComponent = table;
        tablePanel.add(currentComponent, BorderLayout.CENTER);
        isShowing = true;

      } else {
        split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, currentComponent, table);
        splitPos = myPrefs.getInt("splitPos" + level, 500);
        if (splitPos > 0) split.setDividerLocation(splitPos);

        show();
      }
    }
Esempio n. 12
0
    public void actionPerformed(ActionEvent a) {
      // Note that this only works on *nix OSes.
      // For windows, get the first character of the action command, cast it to int, and compare
      // that on a case-by-case basis.

      String command = a.getActionCommand();
      if (command.equals("e")) {
        // Log toggle.
        if (consoleDisplayed = !consoleDisplayed) {
          splitter.add(outputScroll);
          splitter.setDividerLocation(defaultSliderPosition);
        } else {
          splitter.remove(outputScroll);
        }
      } else if (command.equals("r")) {
        // Gets the code into a string.
        String code = text.getText();

        // Marks certain areas as "dirty".
        // Dirty areas are places that shouldn't be considered for any keywords,
        // including "import", "extend", and so on.
        ArrayList<Integer> dirtyBounds = getDirty(code);

        if (text.getText().contains("class")) {
          // This means we should try to compile this as normal.

          // Pulls out class name
          int firstPos = code.indexOf("public class");
          int secondPos = code.indexOf("{");
          String name = code.substring(firstPos + "public class".length() + 1, secondPos).trim();

          // Just a safety check to make sure you don't try to modify this program while it's
          // running.
          if (name.equals("Playground")) {
            System.out.println(
                "I know what you're doing and I don't approve. I won't even compile that.");
            return;
          }

          compileAndRun(name, code);
        } else {
          // This means we should compile this as a playground.

          // Common import statements built-in
          String importDump = new String();
          importDump +=
              ( // "import java.util.*;\n" +
              "import javax.swing.*;\n"
                  + "import javax.swing.event.*;\n"
                  + "import java.awt.*;\n"
                  + "import java.awt.event.*;\n"
                  + "import java.io.*;\n");

          // User-defined or auto-generated methods
          String methodDump = new String();

          // dirtyBounds.forEach(System.out::println);

          // Pulls out any "import" statements and appends them to the import dump.
          int i = code.indexOf("import");
          while (i >= 0) {
            // Ignores comments and string literals
            if (isDirty(dirtyBounds, i)) {
              i = code.indexOf("import", i + 1);
              continue;
            }

            String s = code.substring(i, code.indexOf(";", i) + 1);
            // System.out.println("Found import: " + s);
            code = code.replaceFirst(s, "");
            importDump += s + "\n";
            i = code.indexOf("import", i + 1);
          }

          // Pulls out methods- these are defined by the keyword "method" until a closing bracket.
          /*
          i = code.indexOf("method");
          while(i >= 0) {
          //Ignores comments and string literals
          if (isDirty(dirtyBounds, i)) {
          i = code.indexOf("method", i+1);
          continue;
          }

          //This scans from the first '{' until the last '}' to pull out the full method declaration.
          char temp = 0;
          int pos = code.indexOf("{", i+1), count = 1;
          if(pos != -1) {
          while(++pos < code.length()) {
          if (count == 0)
          break;

          temp = code.charAt(pos);
          if (temp == '{')
          count++;
          if (temp == '}')
          count--;
          }
          } else {
          //Missing an opening bracket, so just remove "method" and hope it compiles.
          code = code.replaceFirst("method", "");
          i = code.indexOf("method", i+1);
          continue;
          }
          String s = code.substring(i, pos);

          //System.out.println("Found method: " + s);
          code = code.replace(s, "");
          methodDump+=(s.replaceFirst("method ", "static ")) + "\n";

          i = code.indexOf("method", i+1);
          }*/

          // Pulls out all methods
          i = code.indexOf("(");
          while (i >= 0) {
            if (isDirty(dirtyBounds, i)) {
              i = code.indexOf("(", i + 1);
              continue;
            }

            // Move backwards first
            char temp = 0;
            int pos = i;
            boolean shouldSkip = false;
            while (--pos > 0) {
              temp = code.charAt(pos);
              if (temp == '.') {
                shouldSkip = true;
                break;
              } // This is a method call, ie String.charAt();
              if (temp == ';') {
                ++pos;
                break;
              } // This is most likely a method declaration, since we had no errors
              // If we hit the start of the file, that's probable a method dec. too!
            }
            if (shouldSkip || isDirty(dirtyBounds, pos)) {
              i = code.indexOf("(", i + 1);
              continue;
            } // If this def. isn't a method or it's in a comment

            int start = pos;
            temp = 0;
            pos = code.indexOf("{", i + 1);
            int count = 1;
            if (pos != -1) {
              while (++pos < code.length()) {
                if (count == 0) break;

                temp = code.charAt(pos);
                if (temp == '{') count++;
                if (temp == '}') count--;
              }
            } else {
              i = code.indexOf("(", i + 1);
              continue;
            }

            int end = pos;
            String s = code.substring(start, end);
            code = code.replace(s, "");

            // Just to make it look nicer
            s = s.trim();

            System.out.println("Found method: " + s);
            methodDump += (s + "\n");
            i = code.indexOf("(", i + 1);
          }

          // Inject the class header and main method, imports, and methods
          code =
              "//User and auto-imports pre-defined\n"
                  + importDump
                  + "//Autogenerated class\n"
                  + "public class Main {\n"
                  + "public static void main(String[] args) {\n"
                  + code
                  + "}\n"
                  + methodDump
                  + "}";

          // Run as normal
          compileAndRun("Main", code);
        }
      } else if (command.equals("k")) {
        kill();
      } else if (command.equals("o")) {
        new OptionFrame(frame);
      } else if (command.equals("/")) {
        new HelpFrame(frame);
      }
    }
Esempio n. 13
0
  public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) {
    this.parentFrame = parentFrame;
    Container cp = this;
    qsadminMain.setGUI(this);
    cp.setLayout(new BorderLayout(5, 5));
    headerPanel = new HeaderPanel(qsadminMain, parentFrame);
    mainCommandPanel = new MainCommandPanel(qsadminMain);
    cmdConsole = new CmdConsole(qsadminMain);
    propertiePanel = new PropertiePanel(qsadminMain);

    if (headerPanel == null
        || mainCommandPanel == null
        || cmdConsole == null
        || propertiePanel == null) {
      throw new RuntimeException("Loading of one of gui component failed.");
    }

    headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    cp.add(headerPanel, BorderLayout.NORTH);
    JScrollPane propertieScrollPane = new JScrollPane(propertiePanel);
    // JScrollPane commandScrollPane = new JScrollPane(mainCommandPanel);
    JSplitPane splitPane =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, mainCommandPanel, cmdConsole);
    splitPane.setOneTouchExpandable(false);
    splitPane.setDividerLocation(250);
    // splitPane.setDividerLocation(0.70);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.addTab("Main", ball, splitPane, "Main Commands");
    tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel");

    QSAdminPluginConfig qsAdminPluginConfig = null;
    PluginPanel pluginPanel = null;
    // -- start of loadPlugins
    try {
      File xmlFile = null;
      ClassLoader classLoader = null;
      Class mainClass = null;

      File file = new File(pluginDir);
      File dirs[] = null;

      if (file.canRead()) dirs = file.listFiles(new DirFileList());

      for (int i = 0; dirs != null && i < dirs.length; i++) {
        xmlFile = new File(dirs[i].getAbsolutePath() + File.separator + "plugin.xml");
        if (xmlFile.canRead()) {
          qsAdminPluginConfig = PluginConfigReader.read(xmlFile);
          if (qsAdminPluginConfig.getActive().equals("yes")
              && qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) {
            classLoader = ClassUtil.getClassLoaderFromJars(dirs[i].getAbsolutePath());
            mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass());
            logger.fine("Got PluginMainClass " + mainClass);
            pluginPanel = (PluginPanel) mainClass.newInstance();
            if (JPanel.class.isInstance(pluginPanel) == true) {
              logger.info("Loading plugin : " + qsAdminPluginConfig.getName());
              pluginPanelMap.put("" + (2 + i), pluginPanel);
              plugins.add(pluginPanel);
              tabbedPane.addTab(
                  qsAdminPluginConfig.getName(),
                  ball,
                  (JPanel) pluginPanel,
                  qsAdminPluginConfig.getDesc());
              pluginPanel.setQSAdminMain(qsadminMain);
              pluginPanel.init();
            }
          } else {
            logger.info(
                "Plugin "
                    + dirs[i]
                    + " is disabled so skipping "
                    + qsAdminPluginConfig.getActive()
                    + ":"
                    + qsAdminPluginConfig.getType());
          }
        } else {
          logger.info("No plugin configuration found in " + xmlFile + " so skipping");
        }
      }
    } catch (Exception e) {
      logger.warning("Error loading plugin : " + e);
      logger.fine("StackTrace:\n" + MyString.getStackTrace(e));
    }
    // -- end of loadPlugins

    tabbedPane.addChangeListener(
        new ChangeListener() {
          int selected = -1;
          int oldSelected = -1;

          public void stateChanged(ChangeEvent e) {
            // if plugin
            selected = tabbedPane.getSelectedIndex();
            if (selected >= 2) {
              ((PluginPanel) pluginPanelMap.get("" + selected)).activated();
            }
            if (oldSelected >= 2) {
              ((PluginPanel) pluginPanelMap.get("" + oldSelected)).deactivated();
            }
            oldSelected = selected;
          }
        });

    // tabbedPane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
    cp.add(tabbedPane, BorderLayout.CENTER);

    buildMenu();
  }
Esempio n. 14
0
 public void setHorizontalDivider(int divider) {
   horizontalSplitPane.setDividerLocation(divider);
 }
Esempio n. 15
0
 public void setVerticalDivider(int divider) {
   verticalSplitPane.setDividerLocation(divider);
 }
Esempio n. 16
0
  public IndexingFrame(Frames parent, BatchState bs) {

    this.parent = parent;
    this.batchState = bs;
    this.indexingFrame = this;

    // Set the window's title
    this.setTitle("Indexing");

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create menu bar
    this.createMenuBar(this);

    this.setPreferredSize(new Dimension(2000, 1000));

    // Set the location of the window on the desktop
    this.setLocation(100, 100);

    // Size the window according to the preferred sizes and layout of its subcomponents
    this.pack();

    Container contentPane = this.getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));

    ButtonBar buttonBar = new ButtonBar(this, batchState);
    contentPane.add(buttonBar);

    JTabbedPane leftTabbedPane = new JTabbedPane();
    formEntry = new FormEntry(this, batchState);
    // TableEntry table = new TableEntry();
    model =
        new DefaultTableModel() {
          @Override
          public boolean isCellEditable(int row, int column) {

            return column != 0;
          }
        };

    //		tableEntry = new JTable(model);
    //		tableEntry.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    //		tableEntry.setColumnSelectionAllowed(true);
    //		tableEntry.setRowSelectionAllowed(true);
    //
    //		tableEntry.setGridColor(Color.BLACK);

    tableEntry = new TableEntry(this, batchState, model);

    JScrollPane scrollpane = new JScrollPane(tableEntry);
    leftTabbedPane.add("Table Entry", scrollpane);

    listModel = new DefaultListModel<String>();
    list = new JList(listModel);
    JScrollPane listScroll = new JScrollPane(list);

    JScrollPane formScroll = new JScrollPane(formEntry);

    JPanel formSplit = new JPanel();
    formSplit.setLayout(new BoxLayout(formSplit, BoxLayout.LINE_AXIS));
    formSplit.add(listScroll);
    formSplit.add(formScroll);

    leftTabbedPane.add("Form Entry", formSplit);

    JTabbedPane rightTabbedPane = new JTabbedPane();
    fieldHelp = new FieldHelp(batchState);
    JScrollPane helpScroll = new JScrollPane(fieldHelp);
    helpScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    ImageNavigation imageNavigation = new ImageNavigation();
    rightTabbedPane.add("Field Help", helpScroll);
    rightTabbedPane.add("Image Navigation", imageNavigation);

    horizontalSplitPane =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftTabbedPane, rightTabbedPane);
    horizontalSplitPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    horizontalSplitPane.setDividerLocation(this.getWidth() / 2);
    horizontalSplitPane.setOneTouchExpandable(true);
    horizontalSplitPane.setResizeWeight(0.5);

    this.imageComponent = new ImageComponent();

    componentPanel = new JPanel();
    // componentPanel.setBackground(Color.gray);
    // componentPanel.setPreferredSize(new Dimension(400,400));
    component = new DrawingComponent(this, batchState);
    componentPanel.add(component, BorderLayout.CENTER);

    //		slider = new JSlider(1, 100, 20);
    //		slider.addChangeListener(sliderChangeListener);
    //		componentPanel.add(slider, BorderLayout.SOUTH);

    verticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, component, horizontalSplitPane);
    verticalSplitPane.setDividerLocation(this.getHeight() / 2);
    verticalSplitPane.setOneTouchExpandable(true);
    verticalSplitPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    verticalSplitPane.setResizeWeight(0.5);

    contentPane.add(verticalSplitPane);

    this.pack();
  }