static std::string addAutograderButton(GWindow& gui, const std::string& text, const std::string& icon) { static Set<char> usedMnemonics; std::string html = "<html><center>" + stringReplace(text, "\n", "<br>") + "</center></html>"; GButton* button = new GButton(html); STATIC_VARIABLE(AUTOGRADER_BUTTONS).add(button); // set mnemonic shortcut char mnemonic = '\0'; for (int i = 0; i < (int) text.length(); i++) { if (isalpha(text[i]) && !usedMnemonics.contains(text[i])) { mnemonic = text[i]; break; } } if (mnemonic) { usedMnemonics.add(mnemonic); button->setMnemonic(mnemonic); button->setAccelerator("ctrl " + charToString(mnemonic)); } if (!icon.empty()) { button->setIcon(icon); button->setTextPosition(SwingConstants::SWING_CENTER, SwingConstants::SWING_BOTTOM); } gui.addToRegion(button, "SOUTH"); return html; }
void radioButtonTest() { GWindow gw; gw.setTitle("Radio Button Test"); GRadioButton* rb1 = new GRadioButton("Red"); GRadioButton* rb2 = new GRadioButton("Green", "", true); GRadioButton* rb3 = new GRadioButton("Blue"); gw.addToRegion(rb1, "SOUTH"); gw.addToRegion(rb2, "SOUTH"); gw.addToRegion(rb3, "SOUTH"); // a second group of buttons GRadioButton* rb4 = new GRadioButton("Black", "N", true); GRadioButton* rb5 = new GRadioButton("White", "N"); gw.addToRegion(rb4, "NORTH"); gw.addToRegion(rb5, "NORTH"); gw.setVisible(true); }
void gtableTest() { GWindow gw; gw.setTitle("GTable Test"); GTable* table = new GTable(5, 3); // table->setColor("#0000cc"); // table->setFont("Monospaced-Bold-20"); // table->setHorizontalAlignment(GTable::Alignment::RIGHT); table->select(0, 1); gw.addToRegion(table, "NORTH"); // GTable* table2 = new GTable(4, 2, 0, 0, 100, 400); // gw.addToRegion(table2, "EAST"); GButton* buttget = new GButton("Get All"); gw.addToRegion(buttget, "SOUTH"); GButton* buttset = new GButton("Set All"); gw.addToRegion(buttset, "SOUTH"); GButton* buttclear = new GButton("Clear"); gw.addToRegion(buttclear, "SOUTH"); GButton* buttrowadd = new GButton("+R"); gw.addToRegion(buttrowadd, "SOUTH"); GButton* buttrowrem = new GButton("-R"); gw.addToRegion(buttrowrem, "SOUTH"); GButton* buttcoladd = new GButton("+C"); gw.addToRegion(buttcoladd, "SOUTH"); GButton* buttcolrem = new GButton("-C"); gw.addToRegion(buttcolrem, "SOUTH"); GButton* buttwidthadd = new GButton("+W"); gw.addToRegion(buttwidthadd, "SOUTH"); GButton* buttwidthrem = new GButton("-W"); gw.addToRegion(buttwidthrem, "SOUTH"); gw.setVisible(true); while (true) { GEvent event = waitForEvent(ACTION_EVENT | TABLE_EVENT | WINDOW_EVENT); if (event.getEventClass() == ACTION_EVENT) { GActionEvent actionEvent(event); if (actionEvent.getSource() == buttget) { for (int row = 0; row < table->numRows(); row++) { for (int col = 0; col < table->numCols(); col++) { cout << "R" << row << "C" << col << "=\"" << table->get(row, col) << "\" "; } cout << endl; } int row, col; table->getSelectedCell(row, col); cout << "selected: R" << row << "C" << col << endl; } else if (actionEvent.getSource() == buttset) { for (int row = 0; row < table->numRows(); row++) { for (int col = 0; col < table->numCols(); col++) { std::string value = "R" + integerToString(row) + "C" + integerToString(col); table->set(row, col, value); } } table->select(1, 2); } else if (actionEvent.getSource() == buttclear) { table->clear(); } else if (actionEvent.getSource() == buttrowadd) { table->resize(table->numRows() + 1, table->numCols()); } else if (actionEvent.getSource() == buttrowrem) { table->resize(table->numRows() - 1, table->numCols()); } else if (actionEvent.getSource() == buttcoladd) { table->resize(table->numRows(), table->numCols() + 1); } else if (actionEvent.getSource() == buttcolrem) { table->resize(table->numRows(), table->numCols() - 1); } else if (actionEvent.getSource() == buttwidthadd) { table->setColumnWidth(1, table->getColumnWidth(1) + 20); } else if (actionEvent.getSource() == buttwidthrem) { table->setColumnWidth(1, table->getColumnWidth(1) - 20); } } else if (event.getEventClass() == WINDOW_EVENT) { if (event.getEventType() == WINDOW_CLOSED) { break; } } else if (event.getEventClass() == TABLE_EVENT) { GTableEvent tableEvent(event); std::cout << "cell updated: " << tableEvent.toString() << std::endl; } } }