Skip to content

Commit

Permalink
Updated to v1.0.2
Browse files Browse the repository at this point in the history
+ Optimized code.
+ TODO Internationalization & Theme.
  • Loading branch information
bangmaple authored Apr 13, 2020
1 parent 98f107b commit fed6409
Show file tree
Hide file tree
Showing 5 changed files with 936 additions and 674 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,42 @@
*
* @author bangmaple
*/
public class CutCopyPasteActionSupport {
private JMenu jMenu;
JPopupMenu popupMenu = new JPopupMenu();

public CutCopyPasteActionSupport() {
init();
}

private void init() {
jMenu = new JMenu("Edit");
addAction(new DefaultEditorKit.CutAction(), KeyEvent.VK_X, "Cut" );
addAction(new DefaultEditorKit.CopyAction(), KeyEvent.VK_C, "Copy" );
addAction(new DefaultEditorKit.PasteAction(), KeyEvent.VK_V, "Paste" );
}

private void addAction(TextAction action, int key, String text) {
action.putValue(AbstractAction.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(key, InputEvent.CTRL_DOWN_MASK));
action.putValue(AbstractAction.NAME, text);
jMenu.add(new JMenuItem(action));
popupMenu.add(new JMenuItem(action));
}

public void setPopup(JTextComponent... components){
if(components == null){
return;
}
for (JTextComponent tc : components) {
tc.setComponentPopupMenu(popupMenu);
}
}

public JMenu getMenu() {
return jMenu;
}
}
public final class CutCopyPasteActionSupport {

private JMenu jMenu;
private JPopupMenu popupMenu;

public CutCopyPasteActionSupport() {
popupMenu = new JPopupMenu();
init();
}

private void init() {
jMenu = new JMenu("Edit");
addAction(new DefaultEditorKit.CutAction(), KeyEvent.VK_X, "Cut");
addAction(new DefaultEditorKit.CopyAction(), KeyEvent.VK_C, "Copy");
addAction(new DefaultEditorKit.PasteAction(), KeyEvent.VK_V, "Paste");
}

private void addAction(final TextAction action, final int key, final String text) {
action.putValue(AbstractAction.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(key, InputEvent.CTRL_DOWN_MASK));
action.putValue(AbstractAction.NAME, text);
jMenu.add(new JMenuItem(action));
popupMenu.add(new JMenuItem(action));
}

public final void setPopup(final JTextComponent... components) {
if (components == null) {
return;
}

for (JTextComponent tc : components) {
tc.setComponentPopupMenu(popupMenu);
}
}

public JMenu getMenu() {
return jMenu;
}
}
59 changes: 19 additions & 40 deletions src/main/java/com/bangmaple/jdbcgenerator/DraggableTabbedPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,67 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;

public class DraggableTabbedPane extends JTabbedPane {

private boolean dragging = false;
private Image tabImage = null;
private Point currentMouseLocation = null;
private int draggedTabIndex = 0;
private boolean dragging;
private Image tabImage;
private Point currentMouseLocation;
private int draggedTabIndex;

public DraggableTabbedPane(final JFrame parent) {
super();
initVar();
mouseMotionAdapterActionListener(parent);
mouseAdapterActionListener();
}

private void initVar() {
dragging = false;
tabImage = null;
currentMouseLocation = null;
draggedTabIndex = 0;
}

private void mouseMotionAdapterActionListener(final JFrame parent) {
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {

if (!dragging) {
// Gets the tab index based on the mouse position
int tabNumber = getUI().tabForCoordinate(DraggableTabbedPane.this, e.getX(), e.getY());

if (tabNumber >= 0) {
draggedTabIndex = tabNumber;
Rectangle bounds = getUI().getTabBounds(DraggableTabbedPane.this, tabNumber);

// Paint the tabbed pane to a buffer
Image totalImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics totalGraphics = totalImage.getGraphics();
totalGraphics.setClip(bounds);
// Don't be double buffered when painting to a static image.
setDoubleBuffered(false);
paintComponent(totalGraphics);

// Paint just the dragged tab to the buffer
tabImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB);
Graphics graphics = tabImage.getGraphics();
graphics.drawImage(totalImage, 0, 0, bounds.width, bounds.height, bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, DraggableTabbedPane.this);

dragging = true;
repaint();
}
int thisX = parent.getLocation().x;
int thisY = parent.getLocation().y;

int xMoved = e.getX() - currentMouseLocation.x;
int yMoved = e.getY() - currentMouseLocation.y;

int X = thisX + xMoved;
int Y = thisY + yMoved;
parent.setLocation(X, Y);
} else {
currentMouseLocation = e.getPoint();

// Need to repaint
repaint();
}

super.mouseDragged(e);
}
});
}

private void mouseAdapterActionListener() {
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
Expand All @@ -89,7 +88,6 @@ public void mousePressed(MouseEvent e) {

@Override
public void mouseReleased(MouseEvent e) {

if (dragging) {
int tabNumber = getUI().tabForCoordinate(DraggableTabbedPane.this, e.getX(), 10);

Expand All @@ -100,7 +98,6 @@ public void mouseReleased(MouseEvent e) {
insertTab(title, null, comp, null, tabNumber);
}
}

dragging = false;
tabImage = null;
}
Expand All @@ -110,26 +107,8 @@ public void mouseReleased(MouseEvent e) {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);

// Are we dragging?
if (dragging && currentMouseLocation != null && tabImage != null) {
// Draw the dragged tab
g.drawImage(tabImage, currentMouseLocation.x, currentMouseLocation.y, this);
}
}

// public static void main(String[] args) {
// JFrame test = new JFrame("Tab test");
// test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// test.setSize(400, 400);
//
// DraggableTabbedPane tabs = new DraggableTabbedPane();
// tabs.addTab("One", new JButton("One"));
// tabs.addTab("Two", new JButton("Two"));
// tabs.addTab("Three", new JButton("Three"));
// tabs.addTab("Four", new JButton("Four"));
//
// test.add(tabs);
// test.setVisible(true);
// }
}
136 changes: 106 additions & 30 deletions src/main/java/com/bangmaple/jdbcgenerator/MainController.form
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
<Component id="lblLogo" min="-2" pref="265" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="lblLogoJDBC" min="-2" pref="162" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="lblMin" min="-2" pref="30" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
Expand Down Expand Up @@ -98,11 +96,6 @@
<Component id="lblLogoJDBC" max="32767" attributes="0"/>
</Group>
<Component id="lblMin" alignment="0" min="-2" pref="30" max="-2" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jTabbedPane1" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
Expand Down Expand Up @@ -622,21 +615,15 @@
<Component id="txtIP" alignment="0" pref="200" max="32767" attributes="0"/>
<Component id="txtDBName" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="46" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="61" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel8" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel6" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel4" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="txtPort" pref="155" max="32767" attributes="0"/>
<Component id="txtPassword" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="jLabel6" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel4" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="txtPort" pref="155" max="32767" attributes="0"/>
<Component id="txtPassword" max="32767" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
Expand All @@ -663,7 +650,6 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel7" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtDBName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
Expand Down Expand Up @@ -714,10 +700,8 @@
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtDBName">
</Component>
<Component class="javax.swing.JLabel" name="jLabel8">
<Properties>
<Property name="text" type="java.lang.String" value="(Leave blank for &apos;master&apos;)"/>
<Property name="text" type="java.lang.String" value="master"/>
</Properties>
</Component>
</SubComponents>
Expand Down Expand Up @@ -1485,6 +1469,103 @@
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel5">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Preferences">
<Property name="tabTitle" type="java.lang.String" value="Preferences"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel19" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel20" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jComboBox1" max="32767" attributes="0"/>
<Component id="jComboBox2" pref="125" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace pref="513" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="12" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel19" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jComboBox1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jComboBox2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel20" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="356" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel19">
<Properties>
<Property name="text" type="java.lang.String" value="Language:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="jComboBox1">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="2">
<StringItem index="0" value="en-US"/>
<StringItem index="1" value="vi-VN"/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="jLabel20">
<Properties>
<Property name="text" type="java.lang.String" value="Theme:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="jComboBox2">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="3">
<StringItem index="0" value="Dark Mode"/>
<StringItem index="1" value="White Mode"/>
<StringItem index="2" value="Ocean Mode"/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="jLabel17">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt;fb.com/BangMaple&lt;br/&gt;github.com/BangMaple&lt;/html&gt;"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="lblMaxMin">
Expand Down Expand Up @@ -1532,11 +1613,6 @@
<Property name="text" type="java.lang.String" value="Project path:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel17">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt;fb.com/BangMaple&lt;br/&gt;github.com/BangMaple&lt;/html&gt;"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="txtInfo">
</Component>
</SubComponents>
Expand Down
Loading

0 comments on commit fed6409

Please sign in to comment.