/** * Constructor. * * @param l label of the menu item * @param k key shortcut * @param h help string * @param d requires a database to be opened * @param c displays a checkbox, indicating the current selection state */ GUICommands(final String l, final String k, final String h, final boolean d, final boolean c) { label = l; key = k; help = BaseXLayout.addShortcut(h, k); data = d; checked = c; }
/** Adds a tab for creating new tabs. */ private void addCreateTab() { final BaseXButton add = tabButton("e_new"); add.setRolloverIcon(BaseXLayout.icon("e_new2")); add.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { addTab(); refreshControls(true); } }); tabs.add(new BaseXBack(), add, 0); tabs.setEnabledAt(0, false); }
/** * Adds a new editor tab. * * @return editor reference */ EditorArea addTab() { final EditorArea edit = new EditorArea(this, newTabFile()); edit.setFont(GUIConstants.mfont); final BaseXBack tab = new BaseXBack(new BorderLayout(10, 0)).mode(Fill.NONE); tab.add(edit.label, BorderLayout.CENTER); final BaseXButton close = tabButton("e_close"); close.setRolloverIcon(BaseXLayout.icon("e_close2")); close.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { close(edit); } }); tab.add(close, BorderLayout.EAST); tabs.add(edit, tab, tabs.getComponentCount() - 2); return edit; }
/** * Default constructor. * * @param man view manager */ public EditorView(final ViewNotifier man) { super(EDITORVIEW, man); if (Prop.langright) applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); border(6, 6, 6, 6).layout(new BorderLayout(0, 2)).setFocusable(false); header = new BaseXLabel(EDITOR, true, false); final BaseXButton srch = new BaseXButton(gui, "search", H_REPLACE); final BaseXButton openB = BaseXButton.command(GUICommands.C_EDITOPEN, gui); final BaseXButton saveB = new BaseXButton(gui, "save", H_SAVE); hist = new BaseXButton(gui, "hist", H_RECENTLY_OPEN); final BaseXBack buttons = new BaseXBack(Fill.NONE); buttons.layout(new TableLayout(1, 4, 1, 0)); buttons.add(srch); buttons.add(openB); buttons.add(saveB); buttons.add(hist); final BaseXBack b = new BaseXBack(Fill.NONE).layout(new BorderLayout(8, 0)); if (Prop.langright) { b.add(header, BorderLayout.EAST); b.add(buttons, BorderLayout.WEST); } else { b.add(header, BorderLayout.CENTER); b.add(buttons, BorderLayout.EAST); } add(b, BorderLayout.NORTH); tabs = new BaseXTabs(gui); tabs.setFocusable(false); final SearchEditor se = new SearchEditor(gui, tabs, null).button(srch); search = se.panel(); addCreateTab(); add(se, BorderLayout.CENTER); // status and query pane search.editor(addTab(), false); info = new BaseXLabel().setText(OK, Msg.SUCCESS); pos = new BaseXLabel(" "); posCode.invokeLater(); stop = new BaseXButton(gui, "stop", H_STOP_PROCESS); stop.addKeyListener(this); stop.setEnabled(false); go = new BaseXButton(gui, "go", H_EXECUTE_QUERY); go.addKeyListener(this); filter = BaseXButton.command(GUICommands.C_FILTER, gui); filter.addKeyListener(this); filter.setEnabled(false); final BaseXBack status = new BaseXBack(Fill.NONE).layout(new BorderLayout(4, 0)); status.add(info, BorderLayout.CENTER); status.add(pos, BorderLayout.EAST); final BaseXBack query = new BaseXBack(Fill.NONE).layout(new TableLayout(1, 3, 1, 0)); query.add(stop); query.add(go); query.add(filter); final BaseXBack south = new BaseXBack(Fill.NONE).border(4, 0, 0, 0); south.layout(new BorderLayout(8, 0)); south.add(status, BorderLayout.CENTER); south.add(query, BorderLayout.EAST); add(south, BorderLayout.SOUTH); refreshLayout(); // add listeners saveB.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JPopupMenu pop = new JPopupMenu(); final StringBuilder mnem = new StringBuilder(); final JMenuItem sa = GUIMenu.newItem(GUICommands.C_EDITSAVE, gui, mnem); final JMenuItem sas = GUIMenu.newItem(GUICommands.C_EDITSAVEAS, gui, mnem); GUICommands.C_EDITSAVE.refresh(gui, sa); GUICommands.C_EDITSAVEAS.refresh(gui, sas); pop.add(sa); pop.add(sas); pop.show(saveB, 0, saveB.getHeight()); } }); hist.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JPopupMenu pm = new JPopupMenu(); final ActionListener al = new ActionListener() { @Override public void actionPerformed(final ActionEvent ac) { open(new IOFile(ac.getActionCommand())); } }; final StringList sl = new StringList(); for (final EditorArea ea : editors()) sl.add(ea.file.path()); for (final String en : new StringList().add(gui.gprop.strings(GUIProp.EDITOR)).sort(!Prop.WIN, true)) { final JMenuItem it = new JMenuItem(en); it.setEnabled(!sl.contains(en)); pm.add(it).addActionListener(al); } pm.show(hist, 0, hist.getHeight()); } }); refreshHistory(null); info.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { EditorArea ea = getEditor(); if (errFile != null) { ea = find(IO.get(errFile), false); if (ea == null) ea = open(new IOFile(errFile)); tabs.setSelectedComponent(ea); } if (errPos == -1) return; ea.jumpError(errPos); posCode.invokeLater(); } }); stop.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { stop.setEnabled(false); go.setEnabled(false); gui.stop(); } }); go.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { getEditor().release(Action.EXECUTE); } }); tabs.addChangeListener( new ChangeListener() { @Override public void stateChanged(final ChangeEvent e) { final EditorArea ea = getEditor(); if (ea == null) return; search.editor(ea, true); gui.refreshControls(); posCode.invokeLater(); } }); BaseXLayout.addDrop( this, new DropHandler() { @Override public void drop(final Object file) { if (file instanceof File) open(new IOFile((File) file)); } }); }
@Override void drawRectangles(final Graphics g, final MapRects rects, final float scale) { // some additions to set up borders final MapRect l = view.layout.layout; l.x = (int) scale * l.x; l.y = (int) scale * l.y; l.w = (int) scale * l.w; l.h = (int) scale * l.h; final int ww = view.getWidth(); final int hh = view.getWidth(); final Data data = view.gui.context.data(); final int fsz = GUIConstants.fontSize; final int off = gopts.get(GUIOptions.MAPOFFSETS); final int rs = rects.size; for (int ri = 0; ri < rs; ++ri) { // get rectangle information final MapRect r = rects.get(ri); final int pre = r.pre; // level 1: next context node, set marker pointer to 0 final int lvl = r.level; final boolean full = r.w == ww && r.h == hh; Color col = color(rects, ri); final boolean mark = col != null; r.pos = view.gui.context.marked.ftpos != null ? view.gui.context.marked.ftpos.get(data, pre) : null; g.setColor(mark ? col : GUIConstants.color(lvl)); if (r.w < l.x + l.w || r.h < l.y + l.h || off < 2 || ViewData.leaf(gopts, data, pre)) { g.fillRect(r.x, r.y, r.w, r.h); } else { // painting only border for non-leaf nodes.. g.fillRect(r.x, r.y, l.x, r.h); g.fillRect(r.x, r.y, r.w, l.y); g.fillRect(r.x + r.w - l.w, r.y, l.w, r.h); g.fillRect(r.x, r.y + r.h - l.h, r.w, l.h); } if (!full) { col = mark ? GUIConstants.colormark3 : GUIConstants.color(lvl + 2); g.setColor(col); g.drawRect(r.x, r.y, r.w, r.h); col = mark ? GUIConstants.colormark4 : GUIConstants.color(Math.max(0, lvl - 2)); g.setColor(col); g.drawLine(r.x + r.w, r.y, r.x + r.w, r.y + r.h); g.drawLine(r.x, r.y + r.h, r.x + r.w, r.y + r.h); } // skip drawing of string if there is no space if (r.w <= 3 || r.h < GUIConstants.fontSize) continue; r.x += 3; r.w -= 3; final int kind = data.kind(pre); if (kind == Data.ELEM || kind == Data.DOC) { g.setColor(Color.black); g.setFont(GUIConstants.font); BaseXLayout.chopString(g, ViewData.name(gopts, data, pre), r.x, r.y, r.w, fsz); } else { g.setColor(GUIConstants.color(r.level * 2 + 8)); g.setFont(GUIConstants.mfont); final byte[] text = ViewData.content(data, pre, false); r.thumb = MapRenderer.calcHeight(g, r, text, fsz) >= r.h; if (r.thumb) { MapRenderer.drawThumbnails(g, r, text, fsz); } else { MapRenderer.drawText(g, r, text, fsz); } } r.x -= 3; r.w += 3; } }